gpt4 book ai didi

html - 防止 CSS clip-path 剪裁 child ?

转载 作者:太空狗 更新时间:2023-10-29 13:53:46 29 4
gpt4 key购买 nike

有什么方法可以防止 clip-path 剪掉它的 child 吗?例如,考虑以下代码:

.el {
width: 300px;
height: 300px;
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
background-color: orangered;
}

h1 {
position: relative;
z-index: 100;
}
<div class="el">
<h1>Work Hard, Play Hard</h1>
</div>

Codepen

最佳答案

考虑伪元素:

.el {
width: 300px;
height: 300px;
position:relative;
z-index:0;
}
.el::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
background-color: orangered;
}
<div class="el">
<h1>Work Hard, Play Hard</h1>
</div>

关于html - 防止 CSS clip-path 剪裁 child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44154783/

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