【问题标题】:Set List Item (li) exactly in center of page将列表项 (li) 设置在页面中心
【发布时间】:2016-07-26 18:02:37
【问题描述】:

这是我的简单代码:

<ul>
  <li>
      Example1
  </li>
  <li>
      Example12
  </li>
  <li>
      Example13
  </li>
</ul>

用这个css:

ul
{
    text-align: center;
    margin: 0;
    padding: 3vh;
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: #333;
    overflow: hidden;
    list-style-type: none;
}
li
{
    display: inline;
}

"Example1" 并不完全位于页面中心。 这就是现在的样子(black 行表示页面中心,将"Home" 替换为"Example1"):

我怎样才能让它看起来像这样(black line mean center of page):

【问题讨论】:

  • 请正确提出您的问题。

标签: html css web


【解决方案1】:

定义你的lidisplay:inline-block;和你的ul定义box-sizing:border-boxleft:0;right:0;

ul
{
    text-align: center;
    margin: 0;
    padding: 3vh;
    position: fixed;
    bottom: 0;
    left:0;right:0;
    background-color: #333;
    overflow: hidden;
    list-style-type: none;box-sizing:border-box
}
li
{
    padding-left: 3vh;
    padding-right: 3vh;
    display: inline-block;
  vertical-align:top;
margin:0;
}
<ul>
  <li>
    Home
  </li>
</ul>

【讨论】:

  • 我测试。没有区别!
  • @mlibre 现在定义你的 ul box-sizing:border-box;
  • @mlibre 现在删除宽度 100% 并在您的 ul 检查中将 left right 0 添加到我更新的答案中
  • @mlibre 你能检查一下这个小提琴jsfiddle.net/6vygcybt 并告诉我这个小提琴有什么问题
  • box-sizing:border-box 解决了这个问题。谢谢。离开和......没有neccesery
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-31
  • 2019-03-24
  • 2020-10-29
  • 1970-01-01
  • 2014-07-08
相关资源
最近更新 更多