[英]Rounded corners for an iframe not working in Safari
So, I know that border-radius
doesn't really work on an iframe
itself, but what you can do to get a similar effect is to wrap that iframe
in a div
, and set the border-radius
on the div itself, like so:所以,我知道border-radius
本身并不真正适用于iframe
本身,但是你可以做些什么来获得类似的效果是将iframe
包装在div
中,然后在 div 本身上设置border-radius
,就像这样:
<div class="modal-iframe-wrapper">
<iframe class="modal-iframe"></iframe>
</div>
.modal-iframe-wrapper {
overflow: hidden;
border-radius: 8px;
}
This, however, doesn't seem to work in Safari, and I couldn't find any other recent workarounds (the few questions/answers about this on SO are pretty outdated by now).然而,这似乎在 Safari 中不起作用,而且我找不到任何其他最近的解决方法(SO 上关于这个的几个问题/答案现在已经过时了)。 Is there a clean solution to this for Safari? Safari 是否有一个干净的解决方案?
What exactly doesn't work? 到底什么不起作用? I have tested it in Safari but it seems to be working. 我已经在Safari中对其进行了测试,但是它似乎可以正常工作。
<div class="modal-iframe-wrapper">
<iframe class="modal-iframe" src="https://example.com"></iframe>
</div>
.modal-iframe-wrapper {
overflow: hidden;
border-radius: 8px;
width: 400px;
height: 400px;
background: red;
}
iframe { widith: 100%; height: 100%; border: 0; }
https://jsfiddle.net/jwb546k6/ https://jsfiddle.net/jwb546k6/
Try adding: overflow: hidden
to the "wrapper" and 尝试添加: overflow: hidden
到“包装”和
width: 100%;
height: 100%;
To the modal-iframe
. 到modal-iframe
。 Then you can change the height using the "wrapper". 然后,您可以使用“包装器”更改高度。
.modal-iframe-wrapper { overflow: hidden; border-radius: 8px; overflow: hidden; height: 500px; width: 500px; } .modal-iframe { width: 100%; height: 100%; }
<div class="modal-iframe-wrapper"> <iframe class="modal-iframe"></iframe> </div>
Apply the border-radius
to the iframe
instead 将border-radius
应用于iframe
.modal-iframe { border-radius: 8px; }
<div class="modal-iframe-wrapper"> <iframe class="modal-iframe"></iframe> </div>
I know this question is old but I ran into this today and none of the above solutions worked. 我知道这个问题很旧,但是今天我遇到了这个问题,上述解决方案均无效。 This is what ended up working for me. 这就是最终为我工作的原因。 I had to add the webkit mask image to the iframe wrapper. 我必须将Webkit蒙版图像添加到iframe包装器中。
.iframe-wrapper{
//other css here
border-radius: 10px;
-webkit-mask-image: -webkit-radial-gradient(white, black);
}
<div class="iframe-wrapper">
<iframe></iframe>
</div>
clip-path
CSS property also worked for me. clip-path
CSS 属性也对我有用。
clip-path: inset(0% 0% 0% 0% round 10px);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.