繁体   English   中英

使用CSS着色重叠Div形状

[英]Coloring Overlapping Div Shapes Using CSS

我是编码的新手,我试图让这些div的交叉部分变成不同的颜色。 我最初的尝试是创建一个带边框规格的第三个div来模仿形状,但我不能让它完美匹配。 下面是标记和样式,描述了我想要的红色正方形和蓝色圆圈重叠,重叠部分为紫色。

 .box { width: 200px; height: 200px; background: red; position: relative; top: 40px; left: -35px; } .shape { width: 250px; height: 250px; background: navy; border-radius: 50%; position: absolute; left: 50px; top: 50px; } #top-left { width: 148px; height: 147px; background: purple; position: absolute; top: 1px; left:2px; border-top-left-radius: 118px; } 
 <div class="box"> <div class="shape"> <div id="top-left"></div> </div> </div> 

有没有更简单的方法来做到这一点,或者是一种让左上边框完美圆润的方法?

添加overflow: hidden; .shape 相对位置top-left 完成!

 .box { width: 200px; height: 200px; background: red; position: relative; top: 40px; } .shape { width: 250px; height: 250px; background: navy; border-radius: 50%; position: absolute; left: 75px; top: 50px; overflow: hidden; } #top-left { width: 150px; height: 150px; background: purple; position: relative; left: -25px; } 
 <div class="box"> <div class="shape"> <div id="top-left"></div> </div> </div> 

输出:

在此输入图像描述

暂无
暂无

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

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