gpt4 book ai didi

css - 在 CSS 中为使用边框制作的自定义形状添加阴影

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

好的,所以在 HTML 中我有一个带有前后伪元素的 div 标签。这是我的 CSS:

.divClass{
background: #41423D;
height:30px;
}
.divClass:before{
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-width :15px 7px 15px 7px;
border-color: transparent #41423D #41423D transparent;
border-style:solid;
position: absolute;
top: 0;
left: -14px;
}
.divClass:after{
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-width :15px 7px 15px 7px;
border-color: transparent transparent #41423D #41423D;
border-style:solid;
position: absolute;
top: 0;
right: -14px;
}

所以,在设计上就变成了这样:

 ___ 
/ \

Now all I need is a shadow on the before and after pseudo elements which are the 2 triangles on either side of the div. The pseudo elements have 0 width and height so using box-shadow is a little tricky.

I need the shadow along the triangle. So, what can I do?

最佳答案

您可以使用 unicode 字符:▲ 来制作三 Angular 形。

在上面应用文本阴影。

如果三 Angular 形的形状不是您想要的,您可以使用 transform: rotate();transform: skewX(); 进行调整两者都是

这有点棘手而且不完美,但它可以工作:

span {
display: inline-block;
font-size: 70px;
transform: skewX(29.5deg);
color: red;
text-shadow: 2px 2px 4px gray;
}
<span>▲</span>

还有其他一些可能性,都在 CSS Tricks 帖子中进行了描述,因此如果需要,请检查它:

https://css-tricks.com/triangle-with-shadow/

如果您认为您也可以检查 filter: drop-shadow()。如果您不需要对所有浏览器的支持,它可能适合您...

编辑:

根据 css 技巧帖子,你不能这样做吗?

.triangle-with-shadow {
transform: rotate(-45deg);
width: 100px;
height: 100px;
position: relative;
overflow: hidden;
box-shadow: 0 20px 10px -17px rgba(0, 0, 0, 0.5);
}
.triangle-with-shadow:after {
content: "";
position: absolute;
width: 50px;
height: 50px;
background: #999;
transform: rotate(45deg); /* Prefixes... */
top: 75px;
left: 25px;
box-shadow: -1px -1px 10px -2px rgba(0, 0, 0, 0.5);
}
<div class="triangle-with-shadow"></div>

如果您只想要描述的形状,另一种可能性是使用透视:

.shape {
background: #41423D;
width: 150px;
height: 150px;
margin: 20px auto;
transform-origin:50% 100%;
transform:perspective(100px) rotateX(30deg);
box-shadow: 2px 2px 15px #41423D;
}
<div class="shape"></div>

关于css - 在 CSS 中为使用边框制作的自定义形状添加阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48193167/

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