CSS center ul list

你离开我真会死。 提交于 2019-12-29 08:15:21

问题


I have this list here: jsfiddle

<div class="footer-location">
    <ul>
        <li>123 Fake St.</li>
        <li>Toronto, Ontario, Y1Y 1Y1</li>
        <li>416-555-5555</li>
        <li><a href="mailto:info@email.com">info@email.com</a></li>
    </ul>
</div>

And I am trying to center the whole list, I tried setting a width and set margin to 0 auto, but it did't do anything, here is my css code:

.footer-location {
    float: left;
    width: 100%;
    padding-right: 20px;
    padding-left: 25px;
    margin: 0 auto;
    text-align: center;
}

.footer-location ul {
    list-style: none;
}

.footer-location ul li {
    color: #808080;
    padding-bottom: 3px;
    font-size: 12px;
    font-family: Arial, Helvetica, sans-serif;
    float: left;
    padding-right: 10px;
}

回答1:


on .footer-location ul li use display:inline-block; instead of float:left;

.footer-location ul li {
display:inline-block;
color: #808080;
padding-bottom: 3px;
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
padding-right: 10px;
}

DEMO: http://jsfiddle.net/pfW2v/2/




回答2:


you dont need the div wrapper, make the li your footer. avoid descendat selectors 'ul li' , use child selectors if you can 'ul > li'. its more effient

I think you can pull off the footer with just this:

fiddle HTML:

            <ul class="footer-location">
                <li>123 Fake St.</li>
                <li>Toronto, Ontario, Y1Y 1Y1</li>
                <li>416-555-5555</li>
               <li><a href="mailto:info@email.com">info@email.com</a></li>
           </ul>

CSS:

.footer-location {
width: 100%;
text-align: center;
list-style: none;
}

.footer-location > li {
color: #808080;
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
display:inline-block;  
padding: 0 5px 3px 0;
}


来源:https://stackoverflow.com/questions/21172989/css-center-ul-list

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