gpt4 book ai didi

html - 如何正确地为我的三 Angular 形添加阴影和渐变?

转载 作者:技术小花猫 更新时间:2023-10-29 12:08:22 25 4
gpt4 key购买 nike

我想做如下设计:

Sample image

我尝试使用 :after:before 但它不起作用。这是我当前的代码:

.design {
background: #ea053a;
display: inline-block;
height: 155px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 228px;
}

.design:before {
border-top: 43px solid #ea053a;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
margin-right: 40px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 55px;
margin-top: 100px;
width: 128px;
}
<div class="design"></div>

如何让它与原始设计保持一致并具有以下两个属性?:

box-shadow: 0 1px 10px 0 rgba(0, 0, 0, 0.2);
background-image: linear-gradient(to bottom, #ea053a, #d0021b);

最佳答案

这是一个带有倾斜变换和drop-shadow 过滤器的想法。你只需要一些额外的元素来正确地拥有渐变。诀窍是反转倾斜以保持渐变方向正确(如果我们处理纯色则不需要)

.box {
width: 150px;
height: 150px;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}

.box span {
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
}

.box span:first-of-type {
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}

.box span:last-of-type {
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
}

.box span::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to bottom, blue , red );
transform-origin: inherit;
}

.box span:first-of-type::before {
transform: skewY(-35deg);
}

.box span:last-of-type::before {
transform: skewY(35deg);
}

p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<span></span><span></span>
<p>29</p>
</div>

CSS triangle linear gradient and shadow

这是我们如何处理左或右渐变。在这种情况下,我们不需要额外的元素,因为倾斜不会影响方向:

.box {
width: 150px;
height: 150px;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}

.box:before,
.box:after{
content:"";
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
background:linear-gradient(to right,blue,red);
background-size:200% 100%;
}

.box:before{
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}

.box:after{
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
background-position:right;
}

p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<p>29</p>
</div>

这里是任意梯度:

.box {
--g:linear-gradient(45deg,blue,red 60%,yellow); /* gradient coloration*/

width: 150px;
height: 150px;
margin:15px;
display:inline-block;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}

.box span {
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
}

.box span:first-of-type {
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}

.box span:last-of-type {
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
}

.box span::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--g);
background-size:200% 100%;
transform-origin: inherit;
}

.box span:first-of-type::before {
transform: skewY(-35deg);
}

.box span:last-of-type::before {
transform: skewY(35deg);
background-position:right;
}

p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<span></span><span></span>
<p>29</p>
</div>

<div class="box" style="--g:linear-gradient(-62deg,blue,red 60%,yellow)">
<span></span><span></span>
<p>29</p>
</div>

CSS gradient and drop shadow

由于每个元素占用 50% 的宽度,我们将背景设置为 200% 以将其大小作为主要容器,然后我们调整位置以创建一个背景的错觉。就好像每个元素都会显示一半的主要背景。


使用掩码的优化版本

.box {
width: 150px;
height: 150px;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box > div {
height: 100%;
background: linear-gradient(35deg, blue, red);
-webkit-mask:
linear-gradient(#fff, #fff) top/100% 70%,
linear-gradient(to bottom right, #fff 49.5%, transparent 50%) bottom right/50% 30%,
linear-gradient(to bottom left, #fff 49.5%, transparent 50%) bottom left /50% 30%;
mask:
linear-gradient(#fff, #fff) top/100% 70%,
linear-gradient(to bottom right, #fff 49.5%, transparent 50%) bottom right/50% 30%,
linear-gradient(to bottom left, #fff 49.5%, transparent 50%) bottom left /50% 30%;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
}
p {
margin: 0;
color: #fff;
font-size: 45px;
line-height: 100px;
text-align: center;
}
<div class="box">
<div>
<p>29</p>
</div>
</div>

或者剪辑路径

.box {
width: 150px;
height: 150px;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box > div {
height: 100%;
background: linear-gradient(35deg, blue, red);
clip-path:polygon(0 0,100% 0,100% 70%,50% 100%,0 70%);
}
p {
margin: 0;
color: #fff;
font-size: 45px;
line-height: 100px;
text-align: center;
}
<div class="box">
<div>
<p>29</p>
</div>
</div>

关于html - 如何正确地为我的三 Angular 形添加阴影和渐变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54550209/

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