如何在 Bootstrap 4 中将卡片(主体和图像)的角变圆?

Mar*_*sio 9 html css

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

线框卡:https://i.stack.imgur.com/gbDFR.jpg

浏览器中的当前卡片:https ://i.stack.imgur.com/i0m7M.jpg

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

.img-rounded{
    border-radius: 20%;
}
Run Code Online (Sandbox Code Playgroud)

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

卡片 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>
Run Code Online (Sandbox Code Playgroud)

Om_*_*_16 6

它很简单,只需简单的CSS即可实现。正如您添加border-radius到图像中一样,您必须将相同的内容添加到包含内容和图像的父元素中......

假设你有<div class="card">,里面有<div class="content">,然后你有你的图像,所以请尝试添加相同的border-radius内容<div class="content">。它应该可以为您解决问题。