简体   繁体   English

如何在CSS3圆形边界处裁剪内部HTML元素?

[英]How do I crop internal HTML elements at CSS3 rounded borders?

I have a div inside another div. 我在另一个div中有一个div。 The outer div has rounded borders using CSS3. 外部div使用CSS3具有圆角边框。 The problem is, if I set a background color on the inner div it bleeds through into the corners. 问题是,如果我在内部div上设置背景色,则会渗入角落。 Here's a test page to show what I mean: http://www.webdevout.net/test?0O 这是一个测试页面,显示我的意思: http : //www.webdevout.net/test?0O

I suspect it's not a renderer issue, as the same thing happens in Chrome, FF, and Opera. 我怀疑这不是渲染器问题,因为Chrome,FF和Opera中会发生相同的情况。 How do I get the inner div to crop at the rounded borders? 如何使内部div在圆角边界处裁剪? Setting border-radius on the inner div to inherit doesn't cut it, the borders don't match up. 将内部div上的border-radius设置为继承不会削减它,边界不匹配。

EDIT: The inner div is actually a header for more content inside the outer div, so applying the rounded borders to the inner div instead will not work. 编辑:内部div实际上是外部div内更多内容的标题,因此将圆角边框应用于内部div无效。

溢出:隐藏应该这样做...或者实际上,它没有...给内部容器添加另一组圆角。

Can you set the rounded corners on your inner div and just use your outer div as the container (unless it's no longer needed, then just get rid of it to remove the unnecessary nesting). 您能否在内部div上设置圆角并仅将外部div用作容器(除非不再需要它,然后将其除去即可删除不必要的嵌套)。

See this example: http://www.webdevout.net/test?0Q 请参见以下示例: http : //www.webdevout.net/test?0Q

I added padding to your inner div and applied all of your CSS classes to the inner div. 我向内部div添加了填充,并将所有CSS类都应用于内部div。

You can't. 你不能 Those areas are occupied by the border of the element and that can't be changed. 这些区域被元素的边界占据,并且无法更改。 That's not to say you can't without extra markup and css to pull it off but, normally, no. 这并不是说您不能没有额外的标记和css将其拉出,但是通常不会。

Round your top corners on the inner div but don't round the bottom corners, like so: 在内部div上使您的顶角变圆,但不要使底角变圆,如下所示:

http://www.webdevout.net/test?0T http://www.webdevout.net/test?0T

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

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