How can I get a <ul> to be evenly spaced across the content area it exists in?

雨燕双飞 提交于 2019-12-05 07:23:26

But of course. I've put together a demo here. The CSS is as follows with explanation as comments:

#SearchForm {
    /* Set width of parent div */
    width: 62.1em;   
}

#SearchForm ul {
    /* Make ul take 100% of its parent's width */
    width: 100%;

    list-style: none;
    padding: 0;
    margin: 15px 0 5px 0;
}

#SearchForm li {
    /* Float the li's left and give them 20% width (20% * 5 = 100%) */
    float: left;
    width: 20%;

    /* Make sure no horizontal padding/margin is applied.  Since we've set an 
       explicit width on the li, horizontal padding/margins would add to this, 
       making the element greater than 20% width and causing float drop */        
    margin: 12px 0 0 0;
    padding: 6px 0;   
}

#SearchForm li a {
    /* Set the nested links to display block and align their text center */
    display: block;
    text-align: center;

    /* Here we can safely apply horizontal padding/margins because we haven't
       explicitly set a width on the element */
    margin: 0 6px 0 0;
    padding: 0 20px;

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