Nic*_*las 18 html css css3 flexbox
我有一个列表,其中包含具有自动宽度的不同项目(在我的情况下,不能给出固定的宽度).我使用justify-content: space-between是因为我的第一个项目必须从容器的开头开始,最后一个项目开始.
所有上述工作都很好,但每当我尝试在这些列表项之间添加一行时,问题就会出现.我无法确定需要多少px或%来定位这些线.有没有办法"动态"定位不同列表项之间的行?
我们使用的html是不可编辑的,因为它是由我们正在使用的CMS呈现的.
这就是我所拥有的:
这是我试图实现的目标
这是我目前的代码
html {
box-sizing: border-box;
}
.Container {
max-width: 70%;
margin-right: auto;
margin-left: auto;
background: blue;
padding-top: 20px;
padding-bottom: 20px;
}
.Flex {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
}
.Flex-item {
background: red;
position: relative;
}
.Flex-item:after {
content: "";
position: absolute;
background: white;
width: 1px;
height: 40px;
top: 50%;
transform: translateY(-50%);
}Run Code Online (Sandbox Code Playgroud)
<div class="Container">
<ul class="Flex">
<li class="Flex-item">Lorem</li>
<li class="Flex-item">consectetur</li>
<li class="Flex-item">vestibulum</li>
<li class="Flex-item">nec</li>
<li class="Flex-item">condimentum</li>
</ul>
</div>Run Code Online (Sandbox Code Playgroud)
Ste*_*erg 17
我正在使用这个解决方案来处理我正在进行的项目.
它设置justify-content: space-between;在弹性容器和flex: 1 1 auto;所有儿童的左边框上,除了第一个.
我修改了你的示例CSS,你可以看看.我不确定你是否会对孩子们有背景颜色,所以我只是用线高来获得更大的边框.
html {
box-sizing: border-box;
}
.Container {
max-width: 70%;
margin-right: auto;
margin-left: auto;
background: blue;
padding-top: 20px;
padding-bottom: 20px;
}
.Flex {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
}
.Flex-item {
flex: 1 1 auto;
background: red;
position: relative;
text-align: center;
line-height: 40px;
}
.Flex-item + .Flex-item {
border-left: solid 1px white;
}
/** Optional for OPs exact layout */
.Flex-item:first-child {
text-align: left;
}
.Flex-item:last-child {
text-align: right;
}Run Code Online (Sandbox Code Playgroud)
<div class="Container">
<ul class="Flex">
<li class="Flex-item">Lorem</li>
<li class="Flex-item">consectetur</li>
<li class="Flex-item">vestibulum</li>
<li class="Flex-item">nec</li>
<li class="Flex-item">condimentum</li>
</ul>
</div>Run Code Online (Sandbox Code Playgroud)
无需修改HTML.
不:after使用风格化的 ARIA 代表性 LI
<li class="separator" aria-hidden="true" role="presentation"></li>
Run Code Online (Sandbox Code Playgroud)
喜欢:
<li class="separator" aria-hidden="true" role="presentation"></li>
Run Code Online (Sandbox Code Playgroud)
.Container {
max-width: 70%;
margin: 0 auto;
background: blue;
}
.Flex {
display: flex;
justify-content: space-between;
list-style: none; padding: 20px 0; margin:0;
}
.Flex-item {
background: red;
}
.separator {
background: white; width: 1px;
}Run Code Online (Sandbox Code Playgroud)
display: list-itemPS:是的,我最初尝试在:after伪上使用,但不。
您可以使用嵌套es使其工作- 我知道您无法更改标记,但至少您必须将 es 的内容包装成我在这里的样子: flexboxlispan
做.flex-item也flexbox有一个文本span(这将有现在的红色背景)和分离器作为一个:after元素
应用flex-grow和flex-shrink为1,flex-basis到auto了Flex-item。
在flex: 0最后Flex-item,并margin-auto到:after也有助于效果。
演示可能会更好地解释它 - 见下文:
html {
box-sizing: border-box;
}
.Container {
max-width: 70%;
margin-right: auto;
margin-left: auto;
background: blue;
padding-top: 20px;
padding-bottom: 20px;
}
.Flex {
display: flex;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
}
.Flex-item {
display: flex;
justify-content: space-between;
align-items: center;
flex: 1 1 auto;
}
.Flex-item span {
background: red;
}
.Flex-item:not(:last-child):after {
content: "";
border: 1px solid white;
height: 40px;
margin: auto;
}
.Flex-item:last-child {
flex: 0;
}Run Code Online (Sandbox Code Playgroud)
<div class="Container">
<ul class="Flex">
<li class="Flex-item">
<span>Lorem</span>
</li>
<li class="Flex-item">
<span>consectetur</span>
</li>
<li class="Flex-item">
<span>vestibulum</span>
</li>
<li class="Flex-item">
<span>nec</span>
</li>
<li class="Flex-item">
<span>condimentum</span>
</li>
</ul>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11973 次 |
| 最近记录: |