简体   繁体   English

在不使用CSS剪切路径的情况下设置iframe的包装div的样式

[英]Style an iframe's wrapper div without css clip-path

I want to find a replacement for CSS's clip-path to assure cross-browser compatibility with internet explorer, edge and safari for the following issue. 我想找到CSS的剪切路径的替代品,以确保跨浏览器与Internet Explorer,Edge和Safari的跨浏览器兼容性,以解决以下问题。

The following example shows what I want to do, an iframe component wrapped in a style div with variable border size: 以下示例显示了我想做的事情,一个包裹在样式div中的iframe组件,其边框大小可变:

在此处输入图片说明

I was able to somewhat replicate this style with clip-path using rotated squares at the cutted out corners and removed the "excess" square with clip-path as you can see in the following image of my component: 我可以在切出的角上使用旋转的正方形在某种程度上复制带有剪切路径的样式,并通过剪切路径删除“多余的”正方形,如您在组件的下图中所示:

在此处输入图片说明

The problem arises when I test this component in internet edge, since the latter does not have support to clip-path the squares are never clipped and it appears as so: 当我在Internet Edge中测试此组件时会出现问题,因为后者不支持剪切路径,因此正方形永远不会被剪切,因此它看起来像这样:

在此处输入图片说明

As you can verify my styled wrapper is not even similar to the original example, also it does not work in all browsers... 您可以确认我的样式化包装器与原始示例甚至都不相似,因此它并非在所有浏览器中都适用...

So I am asking for some guidance in what I can do to make this styled div wrapper be supported in all browsers and be somewhat more similar to the original example. 因此,我要求我提供一些指导,以使该样式的div包装器在所有浏览器中得到支持,并使它与原始示例更加相似。

I have read this can be done with :before and :after div compositions but that does not allow me to completely wrap the iframe component. 我已经读过可以使用:before:after div组合完成此操作,但这不允许我完全包装iframe组件。 Also, I have read about svg masking which can not also be used due the reason of the former. 另外,由于前者的原因,我已经阅读了有关svg掩码的信息,因此也无法使用。

Any help is appreciated. 任何帮助表示赞赏。

 .preview { width: calc(100vw / 20); height: calc(100vh / 10); background: rgba(83, 80, 131, 0.5); cursor: pointer; clip-path: polygon( 10px 0%, 100% 0%, 100% 0%, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0% 100%, 0% 100%, 0% 10px); } .border-corner { transition: all 0.2s ease-in; background: #e9f396; transform: rotate(45deg); bottom: -15; right: -15; width: 30px; height: 30px; position: absolute; } 
 <div class="preview center"> <img class="image" src="https://static.independent.co.uk/s3fs-public/thumbnails/image/2017/09/12/11/naturo-monkey-selfie.jpg?w968" /> </div> <div class="border-corner"></div> 

You can consider a pseudo element over the iframe that you style using multiple background: 您可以考虑使用多个背景对iframe设置样式的伪元素:

 .box { display:inline-block; background:blue; position:relative; } .box:before { content:""; position:absolute; top:20px; left:20px; bottom:20px; right:20px; background: /*top left corner*/ linear-gradient(to top left ,transparent 49.8%,blue 50%) top left/30px 30px, linear-gradient(to top left ,transparent 49.8%,grey 50%) top left/37px 37px, /*bottom right corner*/ linear-gradient(to bottom right,transparent 49.8%,blue 50%) bottom right/30px 30px, linear-gradient(to bottom right,transparent 49.8%,grey 50%) bottom right/50px 50px, /*borders*/ linear-gradient(grey,grey) top /100% 5px, linear-gradient(grey,grey) bottom /100% 5px, linear-gradient(grey,grey) right /5px 100%, linear-gradient(grey,grey) left /5px 100%; background-repeat:no-repeat; } iframe { display:block; margin:20px; background:red; border:none; } 
 <div class="box"> <iframe scr=""></iframe> </div> 

If you can use mask , you can get a CSS only solution. 如果可以使用mask ,则可以获得仅CSS的解决方案。 Please note: That excludes IE 10 and IE 11 and it only works in Edge 18+ (partially). 请注意: 不包括 IE 10和IE 11,并且仅在Edge 18+(部分)中工作。

caniuse.com caniuse.com

However, without clip-path or mask , I highly doubt you will find a solution which makes it look equal in every browser while also allowing you to see what's in the background (assuming you want that element to be "floating" via absolute positioning or something alike). 但是,如果没有clip-pathmask ,我非常怀疑您会找到一种解决方案,使其在每个浏览器中看起来都一样,同时还允许您查看背景中的内容(假设您希望该元素通过绝对定位“浮动”或相似的东西)。 For non-supporting browsers, maybe you should consider having a "simple" box. 对于不支持的浏览器,也许您应该考虑使用“简单”框。

 .shape { position: relative; width: 200px; height: 200px; background: #c00; box-shadow: 0 0 0 5px #000 inset; overflow: hidden; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='47' height='49'%3E%3Cpath d='M11.23 0L0 11.23V49h35.77L47 37.77V0H11.23z'/%3E%3C/svg%3E") 0 0/200px 200px; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='47' height='49'%3E%3Cpath d='M11.23 0L0 11.23V49h35.77L47 37.77V0H11.23z'/%3E%3C/svg%3E") 0 0/200px 200px; } .shape:before, .shape:after { content: ''; display: block; position: absolute; } .shape:before { top: 0; left: 0; border-style: solid; border-width: 55px 55px 0 0; border-color: #000 transparent transparent transparent; } .shape:after { bottom: 0; right: 0; border-style: solid; border-width: 0 0 70px 70px; border-color: transparent transparent #000 transparent; } .shape_content { display: block; width: 100%; height: 100%; border: 0 none; } 
 <div class="shape"> <iframe src="#foo" class="shape_content"></iframe> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM