How to center a navigation bar with CSS or HTML?

后端 未结 6 1458
慢半拍i
慢半拍i 2020-12-05 11:58

I am having difficulty with centering the navigation bar on this page.

I tried nav { margin: 0 auto; } and a bunch of other ways, but I still can\'t cen

6条回答
  •  感情败类
    2020-12-05 12:46

    The best way to fix it I have looked for the code or trick how to center nav menu and found the real solutions it works for all browsers and for my friends ;)

    Here is how I have done:

    body {
        margin: 0;
        padding: 0;
    }
    
    div maincontainer {
        margin: 0 auto;
        width: ___px;
        text-align: center;
    }
    
    ul {
        margin: 0;
        padding: 0;
    }
    
    ul li {
        margin-left: auto;
        margin-right: auto;
    }
    

    and do not forget to set doctype html5

提交回复
热议问题