我目前正在学习CSS网格,并且被要求通过将其分解为网格来制作这张卡片。附上了我想要制作的网格的图片。
实际上有一个更大的网格(在CSS中称为profile-grid),所有这些卡片都排列在其中,这个更大的网格的高度为255px。我想让卡片和卡片内部的网格都遵循这个255px的高度,我成功地使卡片本身的高度正确,但是内部网格的高度却没有。内部网格本身由2行组成,第一行是图片,高度为150px,第二行设置为1fr,但是我无法使内部网格的高度为255px。有哪个地方出错了吗?
https://i.stack.imgur.com/g9Eh6.png
以下是jsFiddle链接:https://jsfiddle.net/40tnwd1o/
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
body {
font-family: roboto;
}
p {
display: block;
margin: auto;
}
.profile-card {
margin-top: 0px;
width: 150px;
height: 255px;
border: none;
box-shadow: 0px 0px 5px 3px rgba(73, 73, 73, 0.301);
}
.profile-grid {
display: grid;
grid-template-columns: 100%;
grid-template-rows: 150px 1fr;
}
.social-ava {
width: 100%;
height: 100%;
background-color: gray;
transition: opacity 0.15s;
}
.social-ava:hover {
opacity: 0.8;
}
.social-text {
height: 100%;
padding: 8px;
}
.social-name {
margin-top: 0px;
cursor: pointer;
transition: color 0.15s;
}
.social-name:hover {
color: rgb(52, 98, 167);
}
.mutual-grid {
display: grid;
grid-template-columns: 20px 1fr;
margin-top: 6px;
align-items: center;
}
.mutual-pic {
width: 20px;
height: 20px;
background-color: gray;
border-radius: 10px;
cursor: pointer;
}
.mutual-friend {
font-size: 12px;
color: rgb(80, 80, 80);
cursor: pointer;
}
.mutual-friend:hover {
text-decoration: underline;
}
.social-add {
margin-top: 6px;
padding: 8px 16px;
border: none;
border-radius: 4px;
color: white;
background-color: rgb(25, 118, 240);
font-size: 12px;
cursor: pointer;
transition: opacity 0.1s;
}
.social-add:hover {
opacity: 0.8;
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号