gpt4 book ai didi

css - 溢出:隐藏属性不适用于伪类前后

转载 作者:行者123 更新时间:2023-11-28 15:15:08 26 4
gpt4 key购买 nike

基本上,我正在尝试创建一个六边形形状,它内部有一个圆圈,圆圈的多余部分应该被隐藏。演示:https://codepen.io/AskSaikatSinha/pen/jwXNPJ?editors=1100

我的 HTML:

<div class="container">
<div class="radius-rect"></div>
<div class="hex">
<div id="hexagon" >
<div class="semi-cir" ></div>
</div>
</div>
</div>

我的 CSS:

#hexagon {
width: 100px;
height: 55px;
background: #0088CD;
position: absolute;
border-top: 1px solid #0088CD;
border-bottom: 1px solid #0088CD;
border-radius: 2px;

}
#hexagon:before {
content: "";
position: absolute;
top: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 25px solid #0088CD;
border-radius: 2px;

}
#hexagon:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 25px solid #0088CD;
border-radius: 2px;
}
.semi-cir{
position: relative;
left: 10px;
background-color:#00A9F1;
height:100px;
width:100px;
-webkit-border-radius:75px;
-moz-border-radius:75px;
z-index: 1;
overflow: hidden;
}

溢出:隐藏没有任何影响。

最佳答案

尽量给背景色与给“半圆形”的背景色一样。在您提供的链接上应用了相同的技巧:https://codepen.io/AskSaikatSinha/pen/jwXNPJ?editors=1100

#hexagon {
width: 100px;
height: 55px;
background: #0088CD;
position: absolute;
top:50px;
left:50px;
border-top: 1px solid #0088CD;
border-bottom: 1px solid #0088CD;
border-radius: 2px;

}
#hexagon:before {
content: "";
position: absolute;
top: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 25px solid #0088CD;
border-radius: 2px;

}
#hexagon:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 25px solid #0088CD;
border-radius: 2px;
}
.semi-cir{
position: relative;
left: 10px;
background-color:#00A9F1;
height:100px;
width:100px;
-webkit-border-radius:75px;
-moz-border-radius:75px;
z-index: 1;
overflow: hidden;
}
.radius-rect{
height:200px;
background:#00a9f1;
}
<div class="container">
<div class="radius-rect"></div>
<div class="hex">
<div id="hexagon" >
<div class="semi-cir" ></div>
</div>
</div>
</div>

关于css - 溢出:隐藏属性不适用于伪类前后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45043062/

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