html - 选中
问题描述
我试图让 ul 具有不同的宽度。这ul
是弯曲的,我想要ul
(将在一列中的前两项to be 60% in width and the last two items 40%. But my
flex-basis` 不起作用?
.container{
border: 1px solid red;
display:flex;
height: 125px;
}
ul {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: flex-start;
width: 100%;
list-style-type: none;
}
ul li{
margin-bottom: 15px;
border: 1px solid blue;
}
/* li:nth-child(1),
li:nth-child(2){
flex-basis: 60%;
}
li:nth-child(3),
li:nth-child(4){
flex-basis: 40%;
} */
<div class="container">
<ul>
<li>should be 60%</li>
<li>should be 60%</li>
<li>should be 40%</li>
<li>should be 40%</li>
</ul>
</div>
解决方案
去掉左边的填充<ul>
(我假设这就是你想要的)并简单地使用width
而不是指定宽度flex-basis
:
.container{
border: 1px solid red;
display:flex;
height: 125px;
}
ul {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: flex-start;
width: 100%;
list-style-type: none;
padding-left: 0;
}
ul li{
margin-bottom: 15px;
border: 1px solid blue;
}
li:nth-child(1),
li:nth-child(2){
width: 60%;
}
li:nth-child(3),
li:nth-child(4){
width: 40%;
}
<div class="container">
<ul>
<li>should be 60%</li>
<li>should be 60%</li>
<li>should be 40%</li>
<li>should be 40%</li>
</ul>
</div>
推荐阅读
- python - 错误消息说我的目录有语法错误
- python - 如何将线程用于拥抱面变压器
- javascript - 发送 res.status.send() 后 Firebase 调用仍在执行
- java - 来自Android中不同类的setContentView(R.layout.xy)
- javascript - JavaScript `debugger` 关键字是如何工作的?
- bash - 在文本文件的第一行之前插入文件名 - 文件扩展名
- java - 如何在 Spring Boot 中使用 @ManyToMany 正确保存实体?
- javascript - 为什么我在一个简单的 for 循环后又增加了一次?
- c# - 在 SQL Server 上运行完整的 EF 查询
- ruby-on-rails - 是否可以使用片段缓存指定缓存或确定特定调用的缓存命中/未命中率