CSS 只能跨浏览器剪角吗?
有人有现代 CSS 方法来做这样的事情吗?我已经找了很多年了。也许我使用了错误的搜索词?
http://fu2k.org/alex/css/equalheight/divs/clipped
更新:
感谢大家的回复和回复。评论。不幸的是,我的 div 背景是有图案的,并且有一个细实心边框,所以这似乎排除了很多建议。我仍在探索这些想法。也许 javascript 方法是可能的?
Does anyone have a modern CSS method for doing something like this? I've been searching for ages. Maybe I'm using the wrong search terms?
http://fu2k.org/alex/css/equalheight/divs/clipped
UPDATE:
Thanks to all for the replies & comments. Unfortunately the background of my div is patterned and has a thin solid border so this seems to rule out a lot of suggestions. I'm still exploring the ideas. Perhaps a javascript approach is a possibility?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用纯 CSS 实现这一点 - 跨平台,工作到 IE7(我还没有使用 IE6 测试过这一点,但我认为它应该仍然有效)。
这将产生以下效果:
You can achieve this with pure CSS - cross-platform, working down to IE7 (I haven't tested this with IE6, but I think it should still work).
This would produce the following effect:
对于圆角,您可以使用
border-radius
(带或不带供应商前缀)。如果您确实想要与问题中的图像相同的外观,您可以使用两个容器,并应用 CSS-转换(带或不带供应商前缀)+
overflow:hidden
以获得所需的外观。对于不支持这些方法的旧浏览器,必须使用透明背景图像来进行回退。
演示 + 逻辑的进一步解释位于: http://jsfiddle.net/7upkc/1/
HTML :
CSS(跨浏览器支持的供应商特定前缀,在这种情况下忽略 Opera 和 IE):
For rounded corners, you can use the
border-radius
(with and without vendor-prefixes).If you really want the same look as in the image at the question, you can use two containers, and applying CSS-transform (with and without vendor-prefixes) +
overflow:hidden
to get the desired look.A fallback has to be used for older browsers which do not support these methods, by using a transparent background image.
Demo + further explanation of logic at: http://jsfiddle.net/7upkc/1/
HTML:
CSS (vendor-specific prefixed for crossbrowser support, ignored Opera and IE in this case):
没有现代的 CSS 可以做到这一点,只能用于圆角。但您可以使用老式边框绘制剪裁的边缘。看这个例子 http://ago.tanfa.co.uk/css /borders/stacked-cubes.html
There is no modern css for this, only for rounded corners. But you can draw clipped edges with old-school borders. Look at this example http://ago.tanfa.co.uk/css/borders/stacked-cubes.html
这是可以做到的。谷歌搜索“CSS对角线”或三角形,但我记得读过的唯一例子使用了技巧。 这是一个三角形的示例,您可以使用它插入角和设置不透明度或类似的值。但是这可能有更好的信息。
编辑:比这一切更好的是我应该首先提到的: Stu Nichol 的网站。
It can be done. Google for "CSS diagonal corner" or triangle but the only example I recall reading used tricks. Here's an example of a triangle that you might use to insert into a corner and set opacity or some such. But this might have better info on that.
EDIT: Even better than all that is the one I should have referred to in the first place: Stu Nichol's site.