【发布时间】:2020-07-31 05:16:14
【问题描述】:
我尝试使用网格在纯 CSS 中创建卡片。我把卡片分成 4 行。在最后一行,我包含了一个按钮,我希望按钮背景颜色填满整个第 4 行。但是当我输入background-color:#F25F5C 时它并没有填满。如果我试图增加宽度(通过向按钮类添加网格或内联块显示),整个网格的行为会很奇怪(我附上了它的屏幕截图)。甚至overflow: hidden 也不起作用。我该怎么办?
.cards {
display: grid;
grid-template-rows: 3fr 1fr 1fr 1fr;
align-items: center;
justify-content: center;
text-align: center;
width: 200px;
height: auto;
border: 1px solid #fff;
background: #afafaf;
border-radius: 15px;
}
.cards img {
width: 100px;
height: 100px;
border-radius: 100px;
}
.btn-book {
background: #F25F5C;
color: #fff;
}
<div class="cards">
<img src="Resources/Images/dsc0060.jpg" alt="paris-image" class="image">
<h4>PARIS</h4>
<p>$500/4 days</p>
<a class="btn-book" href="#">Book Now</a>
</div>
我设置宽度时的屏幕截图:
【问题讨论】:
-
您需要为按钮添加底部半径。宽度应比边框网格小 2 个像素。设置 btn-book:宽度:198px 和边框半径:0 0 15px 15px