gpt4 book ai didi

html - CSS flex wrap 但没有换行

转载 作者:行者123 更新时间:2023-11-28 10:25:47 27 4
gpt4 key购买 nike

我遇到了 flex-wrap 的问题。我需要 flex-wrap: wrap 来确保图像换行并且不会用完容器。我不需要换行链接。请参阅下面我的问题,我的代码也包含在帖子中。

enter image description here

JSFiddle

HTML

<div class="box">
<div class="image">
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
</div>
<div class="tools">
<a href="#">View details</a>
</div>
</div>

<div class="box">
<div class="image">
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
<a href="#">Lorem ipsum dolor sit amet, consectetur adipisicing dolor sit amet, consectetur.</a>
</div>
<div class="tools">
<a href="#">View details</a>
</div>
</div>

SCSS

.box {
border: 1px solid gray;
width: 100%;
display: flex;
margin-bottom: 15px;
&:after {
content: "";
display: table;
clear: both;
}
.image {
float: left;
width: 60%;
border-right: 1px solid gray;
display: flex;
align-items: center;
flex-wrap: wrap;
padding: 5px;
a {
text-decoration: none;
&:not(:last-of-type) {
margin-right: 5px;
}
}
}
.tools {
float: left;
width: 40%;
padding: 5px;
}
}

最佳答案

您可以通过添加

来实现此目的
.box .image a:last-of-type {
flex: 1 1 0;
}

.box {
border: 1px solid gray;
width: 100%;
display: flex;
margin-bottom: 15px;
}

.box:after {
content: "";
display: table;
clear: both;
}

.box .image {
float: left;
width: 60%;
border-right: 1px solid gray;
display: flex;
align-items: center;
flex-wrap: wrap;
padding: 5px;
}

.box .image a {
text-decoration: none;
}

.box .image a:last-of-type {
flex: 1 1 0;
}

.box .image a:not(:last-of-type) {
margin-right: 5px;
}

.box .tools {
float: left;
width: 40%;
padding: 5px;
}
<div class="box">
<div class="image">
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
</div>
<div class="tools">
<a href="#">View details</a>
</div>
</div>

<div class="box">
<div class="image">
<a href="#"><img src="https://dummyimage.com/80x80/000/fff"></a>
<a href="#">Lorem ipsum dolor sit amet, consectetur adipisicing dolor sit amet, consectetur.</a>
</div>
<div class="tools">
<a href="#">View details</a>
</div>
</div>

关于html - CSS flex wrap 但没有换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52274026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com