CSS Shadow box ::使用边框方法在arrox之后 [英] Css Shadow box ::after arrox with border method

查看:84
本文介绍了CSS Shadow box ::使用边框方法在arrox之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过这种设计实现几个要素:

I’m trying to realise a couples of element with this design :

我也希望具有这样的边界半径:

I also want to have a border radius like this :

我设法做到的事情:

对于第一个div,我没有设法为:: before箭头创建内部框阴影,而为:: after箭头进行框阴影

For the first div, I didn’t managed to do inner box shadow for the ::before arrow and box shadow for the ::after arrow

对于上一个div,我设法做到了,但是当我尝试更改箭头的大小以使其变大时,框阴影不起作用e ...

For the last div, I managed to do it but when I try to change the size of the arrow to make it larger, the box-shadows is not working anymore...

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>

任何人都已经有此问题或知道如何解决这个问题?

Anyone already had this issue or know how to solve this problem?

推荐答案

这适用于剪切路径

.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变量,您可以轻松处理它:

With CSS variables you can easily handle it:

>
.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>

要添加边框半径,您可以按如下所示进行编辑:

To add border radius you can edit like below:

.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 Shadow box ::使用边框方法在arrox之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆