gpt4 book ai didi

html - Css Shadow box::after arrox with border 方法

转载 作者:行者123 更新时间:2023-12-01 21:36:01 25 4
gpt4 key购买 nike

我正在尝试通过此设计实现几个元素:

enter image description here

enter image description here

我也想要这样的边框半径:

enter image description here

我设法做了什么:

对于第一个 div,我没有设法为::before 箭头和::after 箭头做内框阴影

对于最后一个 div,我设法做到了,但是当我尝试更改箭头的大小以使其变大时,box-shadows 不再起作用了......

body {
background-color: white;
}
.test{
margin-top: -30px!important;
}
.test2{
z-index:13;
}
.test3{
z-index:12;
}
.test4{
z-index:11;
}
.test5{
z-index:10;
}
.triangle {
position: relative;
margin: 3em;
padding: 1em;
box-sizing: border-box;
background: white;
box-shadow: 0px 3px 10px 0 black;
}
.triangle::before{
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
top: 0;
left: 40%;
width: 0;
height: 0;
border-style: solid;
border-width: 20px 50px 0 50px;
border-color: lightgrey transparent transparent transparent;
//box-shadow: 0px 3px 10px 0 black;

}
.triangle::after{
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
bottom: -20px;
left: 40%;
width: 0;
height: 0;
border-style: solid;
border-width: 20px 50px 0 50px;
border-color: lightgrey transparent transparent transparent;
//box-shadow: 0px 3px 10px 0 black;

}


.toto::after{
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
bottom: -2em;
left: 50%;
box-sizing: border-box;

border: 1em solid black;
border-color: transparent transparent lightgrey lightgrey;

transform-origin: 0 0;
transform: rotate(-45deg);

box-shadow: -3px 3px 3px 0 rgba(0, 0, 0, 0.4);
}
<div class="triangle test2">Inner box shadow for before content not working</div>


<div class="triangle test test3">box shadow for after content not working</div>

<div class="triangle test test4">Content 3</div>

<div class="triangle test test5">Content 4</div>

<div class="triangle toto">Managed to do it but the arrow is not editable(I want to make it longer)</div>

有人遇到过这个问题或知道如何解决这个问题吗?

最佳答案

这适用于clip-path

.box {
margin: 50px;
height: 100px;
position:relative;
z-index:0;
filter: drop-shadow(0 0 5px #000);
}
.box::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
background: #f2f2f2;
clip-path: polygon(
0 0,
calc(50% - 20px) 0, 50% 20px, calc(50% + 20px) 0, /* top arrow */
100% 0,
100% calc(100% - 20px),
calc(50% - 20px) calc(100% - 20px), 50% 100%, calc(50% + 20px) calc(100% - 20px), /* bottom arrow */
0 calc(100% - 20px));
}
<div class="box"></div>

使用 CSS 变量,您可以轻松处理它:

.box {
--w:40px; /* width of the arrow */
--h:20px; /* height of the arrow */
margin: 50px;
height: 100px;
padding:var(--h) 0;
position:relative;
z-index:0;
filter: drop-shadow(0 0 5px #000);
}
.box::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
background: #f2f2f2;
clip-path: polygon(
0 0,
calc(50% - var(--w)/2) 0, 50% var(--h), calc(50% + var(--w)/2) 0, /* top arrow */
100% 0,
100% calc(100% - var(--h)),
calc(50% - var(--w)/2) calc(100% - var(--h)), 50% 100%, calc(50% + var(--w)/2) calc(100% - var(--h)), /* bottom arrow */
0 calc(100% - var(--h)));
}
<div class="box"></div>

<div class="box" style="--w:60px;"></div>

<div class="box" style="--w:200px;--h:40px"></div>


要添加边框半径,您可以像下面这样编辑:

.box {
--w: 40px; /* width of the arrow */
--h: 20px; /* height of the arrow */
--r: 30px; /* radius */
margin: 50px;
height: 100px;
padding: var(--h) 0;
position: relative;
z-index: 0;
filter: drop-shadow(0 0 5px #000);
}

.box::before,
.box::after {
content: "";
position: absolute;
z-index: -1;
left: 0;
right: 0;
background: #f2f2f2;
}
.box::before {
top: 0;
bottom: var(--h);
border-radius: var(--r);
clip-path: polygon( 0 0, calc(50% - var(--w)/2) 0, 50% var(--h), calc(50% + var(--w)/2) 0, 100% 0, 100% 100%, 0 100%);
}

.box::after {
bottom: 0;
height: var(--h);
clip-path: polygon( 0 0, 100% 0, calc(50% - var(--w)/2) 0, 50% 100%, calc(50% + var(--w)/2) 0);
}
<div class="box"></div>

<div class="box" style="--w:60px;--r:20px"></div>

<div class="box" style="--w:200px;--h:40px;--r:60px"></div>

CSS arrow shape with border-radius and shadow

关于html - Css Shadow box::after arrox with border 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61984793/

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