如何在 Bootstrap 4 中对卡片(正文和图像)的角进行圆角处理?

新手上路,请多包涵

我正在尝试为模拟“食谱应用程序”构建响应式 Web 界面。目前我正在使用 bootstrap 4,但在自定义我的卡片元素以匹配我的线框时遇到了问题。

线框卡: https ://imgur.com/a/XQHaltk

浏览器中的当前卡片: https ://imgur.com/a/kqmBGq4

我已经设法用自定义 CSS 来“修复”我的名片图像的边框半径

.img-rounded{
    border-radius: 20%;
}

然而,我仍然需要让我的卡片元素变圆(就像线框的图片)。这样做的最佳方法是什么?

卡片 HTML:

 <div class="card" style="width: 18rem;">
                <img src="./assets/img/1.jpg" class="card-img-top " alt="Jelo 1">
                <div class="card-body">
                    <h5 class="card-title text-center">Recipe name</h5>
                    <p class="card-text mb-4">Some quick example text to build on the Recipe name and make up the bulk of the card's content.</p>
                    <div class="container mb-2">
                        <a href="#" class="btn btn-primary rounded-pill" style="background-color: #32BF84;">Open</a>
                        <a href="#" class="btn btn-primary rounded-pill" style="background-color: #32BF84;">Edit</a>
                        <a href="#" class="btn btn-primary rounded-pill" style="background-color: #32BF84;">Delete</a>
                    </div>
                </div>
            </div>

原文由 Marko Marchisio 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 727
2 个回答

很简单,只需要简单的CSS就可以实现。正如您已将 border-radius 添加到图像中一样,您必须将其添加到还包含内容和图像的父元素中……

Let’s say you have <div class="card"> , inside it you have <div class="content"> , and then you have your image, So kindly try adding the same border-radius to <div class="content"> 还有。它应该可以为您解决问题。

原文由 Om_16 发布,翻译遵循 CC BY-SA 4.0 许可协议

您可以将相同的规则 border-radius: 20% 添加到 card 元素。

原文由 L. Männer 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题