gpt4 book ai didi

css - 只有四分之一的圆形边框?

转载 作者:太空宇宙 更新时间:2023-11-04 03:51:35 31 4
gpt4 key购买 nike

我正在尝试创建一个带有缩进 Angular 的矩形。所以我有一个带有彩色背景的相对定位的矩形。然后我在每个 Angular 绝对定位了一个圆,这给人的印象是矩形上有缩进的 Angular 。只要我保持矩形和圆形的背景颜色为白色,与页面背景相匹配,这就很好用。

但我希望矩形和圆形的背景都是白色的,与页面背景相匹配,并且两者都有边框。但是当我这样做时,矩形的边框出现在圆圈周围。我已经尝试过 z-index,但它不起作用。有什么建议么?谢谢。

相关代码如下:

<style>
#rect {width:200px; height: 300px;background-color: #fff;position: relative;overflow: hidden; border:1px solid #747474;}
.circle {border-radius: 50%; background-color: #fff; border: 1px solid #747474; width: 50px;height: 50px;position: absolute;}
.topleft {top: -10px;left: -10px;}
.topright {top: -10px;right: -10px;}
.bottomleft {bottom: -10px;left: -10px;}
.bottomright {bottom: -10px;right: -10px;}
</style>
</head>
<body>
<div id ="rect">
<div class ="circle topleft"></div>
<div class ="circle topright"></div>
<div class ="circle bottomleft"></div>
<div class ="circle bottomright"></div>

</div>

最佳答案

你可以使用

#rect {
border: none; // default value
}
#rect:before {
content: "";
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
border:1px solid #747474;
}

Demo

问题是在 overflow: hidden 中,圆圈不能与 #rect 的边框重叠。然后,移除该边框并将其添加到一个伪元素中。

关于css - 只有四分之一的圆形边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23318349/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com