我想以我的UL为中心,但是它不起作用

时间:2018-12-21 15:37:05

标签: html css

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    background-color: #f1f1f1;
    height: 5%;
    position: fixed;
    overflow: hidden;
    top: 0;
    text-align: center; 
}

为什么“文本对齐”不起作用?我也尝试过“证明内容”,但这也行不通。

2 个答案:

答案 0 :(得分:2)

CSS样式->

     ul {
   width: 100%;
 }

尝试检查Chrome开发者工具中的元素。您将知道问题所在。 我发现您没有使用宽度。

通过去除子弹使其美丽

 list-style-type : none;

谢谢

答案 1 :(得分:0)

注意到您在ul中使用了固定属性。如果要使其居中对齐,则需要定义宽度,否则无法完成。 您可以这样做

onCreateView

如果使用左:0 右:0 定义其固定值,则它将占据整个宽度,或者您可以使用

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    background-color: #f1f1f1;
    height: 5%;
    position: fixed;
    overflow: hidden;
    top: 0;
    text-align: center;
    // to take the whole width of screen from left to right
    left: 0;
    right: 0;
    // you might start from left: 32px; and right: 32px; there if you need to make a little padding, otherwise it is better if the padding is created in the li within ul
}

,但是使用 width:100%,可能存在元素可能流出页面的风险。如果您要使用 width:100%,则最好添加 left:0;

希望有帮助

相关问题