How to keep an unordered list centered within the screen?

拥有回忆 提交于 2019-12-25 02:35:12

问题


I have the following unordered list within a div:

<div id="footer">
    <ul>
        <li>Blog</li>
        <li>|</li> 
        <li>About Us</li> 
        <li>|</li> 
        <li>Privacy Policy</li> 
        <li>|</li> 
        <li>Copyright</li> 
        <li>|</li> 
        <li>Contact Us</li> 
        <li>|</li> 
        <li>Press Inquiries</li>
    </ul>
</div>

I want this footer text to stay centered in the screen no matter the width of the window. How would I do this using CSS??


回答1:


#footer{
   text-align:center; 
}



回答2:


Either

#footer_list {text-align:center;}

or

#footer_list {width:500px; margin:0 auto;}



回答3:


This tutorial describes, in part, how to do this.




回答4:


It's possible to center a floated list by using relative positioning too.




回答5:


ul {
    padding:0;
    margin:0;
}
li {
    width: 300px;
    margin: auto;
}


来源:https://stackoverflow.com/questions/1058754/how-to-keep-an-unordered-list-centered-within-the-screen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!