gpt4 book ai didi

html - CSS 六边形边框无法按预期工作

转载 作者:行者123 更新时间:2023-11-28 09:16:24 24 4
gpt4 key购买 nike

我只需要一个六边形边框。我找到了一个生成器网站 CSS Hexagon并准确复制给定的代码。但是我在具有相同文档类型的相同浏览器中得到完全不同的结果。

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.hexagon {
position: relative;
width: 190px;
height: 109.70px;
background-color: #64C7CC;
margin: 54.85px 0;
border-left: solid 10px #ff2828;
border-right: solid 10px #ff2828;
}
.hexagon:before,
.hexagon:after {
content: "";
position: absolute;
z-index: 1;
width: 134.35px;
height: 134.35px;
-webkit-transform: scaleY(0.5774) rotate(-45deg);
-ms-transform: scaleY(0.5774) rotate(-45deg);
transform: scaleY(0.5774) rotate(-45deg);
background-color: inherit;
left: 17.8249px;
}
.hexagon:before {
top: -67.1751px;
border-top: solid 14.1421px #ff2828;
border-right: solid 14.1421px #ff2828;
}
.hexagon:after {
bottom: -67.1751px;
border-bottom: solid 14.1421px #ff2828;
border-left: solid 14.1421px #ff2828;
}
</style>
</head>
<body>
<div class="hexagon">
</div>
</body>
</html>

如您所见,边框不是它应有的样子。

Picture of the Result

那我做错了什么?感谢您的帮助!

最佳答案

显然他们遗漏了您还需要这条规则:

*,*:before,*:after {
box-sizing:border-box;
}

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.hexagon {
position: relative;
width: 190px;
height: 109.70px;
background-color: #64C7CC;
margin: 54.85px 0;
border-left: solid 10px #ff2828;
border-right: solid 10px #ff2828;
}
.hexagon:before,
.hexagon:after {
content: "";
position: absolute;
z-index: 1;
width: 134.35px;
height: 134.35px;
-webkit-transform: scaleY(0.5774) rotate(-45deg);
-ms-transform: scaleY(0.5774) rotate(-45deg);
transform: scaleY(0.5774) rotate(-45deg);
background-color: inherit;
left: 17.8249px;
}
.hexagon:before {
top: -67.1751px;
border-top: solid 14.1421px #ff2828;
border-right: solid 14.1421px #ff2828;
}
.hexagon:after {
bottom: -67.1751px;
border-bottom: solid 14.1421px #ff2828;
border-left: solid 14.1421px #ff2828;
}
*,*:before,*:after {
box-sizing:border-box;
}

</style>
</head>
<body>
<div class="hexagon">
</div>
</body>
</html>

关于html - CSS 六边形边框无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26287914/

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