html - 如何使垂直列表项的高度相同?

标签 html css

<分区>

我试图使垂直列表中的元素具有相同的高度。像这样? enter image description here

但是,我在使元素的高度相同时遇到了问题。到目前为止,我已经创建了这个: enter image description here

以下代码片段可以概述我正在努力实现的目标。

html {
  font-family: 'Rubik', sans-serif;
}

ul#sectors {
  list-style-type: none;
  padding-left: 0;
}

ul#sectors>li {
  background: #08455C;
  color: #fff;
  cursor: pointer;
  width: 120px;
  border-radius: 0;
  position: relative;
  font-size: 16px !important;
  text-transform: capitalize;
  text-align: center;
  display: inline-block;
  margin-right: 10px;
  margin-bottom: 10px;
}

ul#sectors>li>p {
  margin: 20px 0;
}

.center {
  text-align: center;
}
<div class="center">
  <ul id="sectors">
    <li>
      <p>All</p>
    </li>
    <li>
      <p>Business <br>Support</p>
    </li>
    <li>
      <p>Creative</p>
    </li>
    <li>
      <p>Cybersecurity</p>
    </li>
    <li>
      <p>Engineering</p>
    </li>
    <li>
      <p>Finance</p>
    </li>
    <li>
      <p>Hospitality</p>
    </li>
    <li>
      <p>Information Technology</p>
    </li>
    <li>
      <p>Misc.</p>
    </li>
    <li>
      <p>Sales</p>
    </li>
    <li>
      <p>Technical</p>
    </li>
  </ul>
</div>

我的问题的代码笔是 https://codepen.io/mrsalami/pen/XxmVRN

最佳答案

使用 display:flexul 而不是 display:inline-blockli

html{
  font-family: 'Rubik', sans-serif;
}

ul#sectors{
  list-style-type: none;
  padding-left:0;
  display:flex;
}

ul#sectors>li{
  background: #08455C;
  color:#fff;
  cursor: pointer;
  width: 120px;
  border-radius: 0;
  position: relative;
  font-size: 16px !important;
  text-transform: capitalize;
  text-align:center;
  margin-right:10px; 
  margin-bottom:10px;
}

ul#sectors>li>p{
  margin:20px 0;
}

.center {
    text-align: center;
}
<div class="center">
<ul id="sectors">
  <li><p>All</p></li>
  <li><p>Business <br>Support</p></li>
  <li><p>Creative</p></li>
  <li><p>Cybersecurity</p></li>
  <li><p>Engineering</p></li>
  <li><p>Finance</p></li>
  <li><p>Hospitality</p></li>
  <li><p>Information Technology</p></li>
  <li><p>Misc.</p></li>
  <li><p>Sales</p></li>
  <li><p>Technical</p></li>
</ul>
</div>

关于html - 如何使垂直列表项的高度相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52606785/

上一篇:twitter-bootstrap - 响应宽度尺寸(5.5 英寸或更小的移动宽度)

下一篇:html - 如何在不模糊子元素的情况下模糊(css)div

相关文章:

html - 使用 Bootstrap 垂直和水平集中

在 Spring 应用程序中找不到 CSS 文件

css - Wordpress map 导致填充问题

javascript - jQuery $.attr() 问题与选择(下拉)

html - 如何使图像始终居中

html - 浏览器垂直滚动条的高度限制

css - div 的长页面 : Use Effect. 切换以在底部展开一个 div:页面滚动回到顶部

html - 第二列中的中心按钮具有灵活的宽度?

html - 从主题继承 wordpress 页面上的 css

html - margin 属性(property)%