css根据元素调整宽度

时间:2013-10-13 12:55:42

标签: css css3

我正在开发导航菜单

enter image description here

如果看到图像,右侧会留下一些空间, 我怎样才能自动调整那里的空间。

没有固定的元素..它们可以是2,3,4或其他

[目前有4个]

1 个答案:

答案 0 :(得分:1)

实现此目标的最佳方法是使用display: table上的ul将水平导航栏表现为一个表格;和display: table-cell上的li

如果您发布了一些代码,我可以给您更好的指示;但这是一个例子:

    nav { 
        width: 500px; /* This would be set to the width of the existing container */
    }

    nav ul {
        list-style: none;
        margin:0;
        padding:0;
        display: table;
        width: 100%; 
    }

    nav li {
        text-align: center;
        display: table-cell;
    }
    nav a {
        display: block;
        text-align: center;
    }
相关问题