作者:fly-fox | 来源:互联网 | 2023-02-11 08:58
我正在为我的卡片组使用flexbox。问题是,我想柔性项div
与.card
类应保持同样的高度,如果里面的文字.card-block.p
在一个卡牌高度的增加,其余也与卡增加。
这是我的小提琴:https : //jsfiddle.net/a2d758jg/ :
.card-group {
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
max-height: 475px;
background-color: lightgrey;
}
.card img {
width: 100%;
}
.card {
background-color: cornflowerblue;
width: 30%;
margin: 0px;
flex: 2;
border: 1px solid lightgrey;
}
.card-block {
padding: 10px;
background-color: #fff;
}
.card-title {
font-size: 18px;
color: grey;
font-family: verdana, sans;
}
.card-footer {
padding: 15px;
border-top: 1px solid lightgrey;
background-color: lightgrey;
}
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This card hasThis is a wider card with supporting text below as a natural lead-in to additional content. supporting text below as a natural lead-in to additional content.This is a wider card with supporting text below as a natural lead-in to additional
content.
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.
Michael_B..
6
对您的代码进行四个调整:
.card-group {
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
/* max-height:475px; <-- remove */
background-color: lightgrey;
}
.card img {
width: 100%;
}
.card {
background-color: cornflowerblue;
width: 30%;
margin: 0px;
flex: 2;
border: 1px solid lightgrey;
display: flex; /* new */
flex-direction: column; /* new */
}
.card-block {
padding: 10px;
background-color: #fff;
flex: 1; /* new */
}
.card-title {
font-size: 18px;
color: grey;
font-family: verdana, sans;
}
.card-footer {
padding: 15px;
border-top: 1px solid lightgrey;
background-color: lightgrey;
}
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This card hasThis is a wider card with supporting text below as a natural lead-in to additional content. supporting text below as a natural lead-in to additional content.This is a wider card with supporting text below as a natural lead-in to additional
content.
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.
修正的小提琴
1> Michael_B..:
对您的代码进行四个调整:
.card-group {
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
/* max-height:475px; <-- remove */
background-color: lightgrey;
}
.card img {
width: 100%;
}
.card {
background-color: cornflowerblue;
width: 30%;
margin: 0px;
flex: 2;
border: 1px solid lightgrey;
display: flex; /* new */
flex-direction: column; /* new */
}
.card-block {
padding: 10px;
background-color: #fff;
flex: 1; /* new */
}
.card-title {
font-size: 18px;
color: grey;
font-family: verdana, sans;
}
.card-footer {
padding: 15px;
border-top: 1px solid lightgrey;
background-color: lightgrey;
}
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
Card title
This card hasThis is a wider card with supporting text below as a natural lead-in to additional content. supporting text below as a natural lead-in to additional content.This is a wider card with supporting text below as a natural lead-in to additional
content.
Card title
This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.