html - 如何在 html 中划分 3 个相等的部分 li

标签 html css

你好,在下面的代码中,如何将空间划分为所有元素列表,它应该居中。 除了首页如何分成3等份

预期输出: 主页 |关于 |服务

    #section ul {
    	width: 1050px;
    	margin: 1px auto 0 auto;
    	height: 50px;
    	padding: 0;
    	float: relative;
    	border-style: solid;
        border-width: 1px;
    	background-color: #556B2F;
    }

    #section ul li {
    	position: relative;
    	list-style-type: none;
        display: inline;
    }

    #section li:before {
    	content: " | ";
    }

    #section li:first-child:before {
        content: none;
    }
      
    <div id="section">
    	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Service</a></li>
        </ul>
    </div>

最佳答案

您可以使用 display:tabledisplay:table-cell 将列表项拉伸(stretch)到等宽。

#section ul {
  width: 100%;
  max-width: 1050px;
  margin: 1px auto 0 auto;
  height: 50px;
  padding: 0;
  /* float:relative*/
  /* NO Such Property */
  border-style: solid;
  border-width: 1px;
  //background-color:#556B2F;
  display: table;
  text-align: center;
}
#section ul li {
  list-style-type: none;
  display: table-cell;
  border-style: solid;
  border-width: 1px;
  vertical-align: middle;
}
#section ul li a {
display: block;
}
<div id="section">
  <ul>
    <li><a href="#">Home</a>
    </li>
    <li><a href="#">About</a>
    </li>
    <li><a href="#">Service</a>
    </li>
  </ul>
</div>

关于html - 如何在 html 中划分 3 个相等的部分 li,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28673162/

相关文章:

css - 为什么 mix() 不能在 LESSC 中使用我的颜色?

php - 在同一页面中提交表单时显示 ajax 成功或错误消息

html - 我无法选择背景图片

html - 图像在 div 之上

javascript - 没有 jquery 的自定义 JS/CSS 选择替代方案

html - 如果元素具有特定类,是否可以在 CSS 中定义不应用样式?

javascript - 使用 CSS 关键帧和 React 切换幻灯片淡出、幻灯片淡入(返回)

HTML/CSS 表格布局已修复,但希望一个 td 的宽度更小

html - 在 Mozilla 上调整窗口大小后,CSS3 转换开始工作

javascript - Chrome 扩展程序 : How to send html form data to a php page upon button being clicked which redirects to said php page