【问题标题】:Flexbox css unordered list custom stylingFlexbox css 无序列表自定义样式
【发布时间】:2018-02-10 13:10:53
【问题描述】:

我想像下面这样设置我的无序列表
Link to what i want to achive
我的结构如下:

<div class="tabs">
 <ul class="tabs__labels">
  <li class="0">
   <a class="active" href="#">
    <img/>
    <div>something</div>
   </a>
  </li>
  <li class="1">
   <a class="" href="#">
    <img/>
    <div>something1</div>
   </a>
  </li>
  ...
 </ul>
</div>

将列表类命名为 0,1 等并分别设置样式以某种方式实现这种效果是个好主意吗?如何使用 flexbox 来获得类似的效果?我应该将它们分组吗?

【问题讨论】:

  • 这看起来像是 CSS Grids. 的工作
  • 这就是我需要的工具! :) 谢谢!

标签: css flexbox html-lists


【解决方案1】:

这是一个开始吗?

.tabs__labels {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  list-style: none;
  margin: 0;
  padding: 0;
}
.tabs__labels li {
  flex-basis: 45%;
  margin: 20px 0;
  padding: 0;
}

.tabs__labels li:nth-child(odd) {
  display: flex;
  justify-content: flex-end;
}
.tabs__labels li:nth-child(even) {
  display: flex;
}

.tabs__labels li:nth-child(3),
.tabs__labels li:nth-child(4) {
  flex-basis: 35%;
}

.tabs__labels li a {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 40px;
  width: 40px;
  border-radius: 50%;
  border: 1px solid red;
  text-decoration: none;
}

.tabs__labels li:nth-child(1)::before {
  content: 'some text';
  text-decoration: underline;
  margin-right: 10px;  
}

.tabs__labels li:nth-child(2)::after {
  content: 'some text';
  text-decoration: underline;
  margin-left: 10px;  
}
<div class="tabs">
 <ul class="tabs__labels">
  <li>
   <a class="active" href="#">S
   </a>
  </li>
  <li>
   <a class="" href="#">S
   </a>
  </li>
  <li>
   <a class="" href="#">S
   </a>
  </li>
  <li>
   <a class="" href="#">S
   </a>
  </li>
  <li>
   <a class="" href="#">S
   </a>
  </li>
  <li>
   <a class="" href="#">S
   </a>
  </li>
 </ul>
</div>

【讨论】:

  • 这就是我需要的基础! :) 非常感谢 :) 顺便说一句,Blazemonger 不是说这里的网格会更好吗?
  • @PokerCloud 当你要求 Flexbox 时,你得到了一个 :) ... 做事的方法通常不止一种,因为我们大多数时候只看到最终结果的一小部分,我们很难说什么更好(而 Blazemonger 并没有说更好)。到今天为止,Flexbox 有更好的浏览器支持,但如果这不是问题,如果你愿意,可以使用 CSS Grid。
猜你喜欢
  • 1970-01-01
  • 2011-05-06
  • 2016-08-29
  • 1970-01-01
  • 2020-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多