[英]How to make border-radius work in case there is a div tag with an image
I have HTML and CSS like this:我有 HTML 和 CSS 像这样:
.item { width: 100%; height: 768px; background-image: url("https://a0.muscache.com/im/pictures/f1502649-e034-40ab-9fed-7992b7d550c6.jpg?im_w=1200"); background-repeat: no-repeat; background-size: 100% auto; border-radius: 50px 50px; }
<div class='item'></div>
When I resize the browser, the bottom border-radius doesn't work.当我调整浏览器大小时,底部边框半径不起作用。
Change background-size: cover;
改变
background-size: cover;
and you could add background-position: center;
你可以添加
background-position: center;
to center your image.使您的图像居中。
.item { width: 100%; height: 768px; background-image: url("https://a0.muscache.com/im/pictures/f1502649-e034-40ab-9fed-7992b7d550c6.jpg?im_w=1200"); background-repeat: no-repeat; background-position: center; background-size: cover; border-radius:50px 50px; }
<div class='item'></div>
As mentioned in other answers, you might want to use background-size: cover;
如其他答案中所述,您可能需要使用
background-size: cover;
. . It will stretch the image to cover the whole area of the div (so the
border-radius
will be visible).它将拉伸图像以覆盖 div 的整个区域(因此
border-radius
将可见)。
However since the image can be cropped after this change (specifically in the case when it does not have the same aspect-ratio like the area of the div), it might be necessary to use also background-position
to position the background image as you like (by default it is aligned to the top left corner).但是,由于可以在此更改后裁剪图像(特别是在它没有与 div 区域相同的纵横比的情况下),因此可能还需要使用
background-position
来 position 作为背景图像像(默认情况下它与左上角对齐)。
Most probably you will have good results with centering it, but the possibilities are endless;)很可能你会在居中得到很好的结果,但可能性是无穷无尽的;)
background-size: cover;
background-position: center;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.