Stretch horizontal ul to fit width of div

前端 未结 4 1908
梦毁少年i
梦毁少年i 2020-12-01 01:51

For the main nav of my site, there is a 980px wide div with a ul for the main nav links. I am trying to make the nav links stretch to fit the width of the div evenly.

4条回答
  •  借酒劲吻你
    2020-12-01 02:42

    This is the easiest way to do it: http://jsfiddle.net/thirtydot/jwJBd/

    (or with table-layout: fixed for even width distribution: http://jsfiddle.net/thirtydot/jwJBd/59/)

    This won't work in IE7.

    #horizontal-style {
        display: table;
        width: 100%;
        /*table-layout: fixed;*/
    }
    #horizontal-style li {
        display: table-cell;
    }
    #horizontal-style a {
        display: block;
        border: 1px solid red;
        text-align: center;
        margin: 0 5px;
        background: #999;
    }
    

    Old answer before your edit: http://jsfiddle.net/thirtydot/DsqWr/

提交回复
热议问题