css - 如何将盒子阴影转换为线性渐变?
问题描述
我如何将此代码转换为线性渐变?
https://jsfiddle.net/bufpark1/
.box {
box-shadow:
0 0 0 5px teal,
0 0 0 10px black,
0 0 0 15px orange,
0 0 0 20px black,
0 0 0 25px teal,
0 0 0 30px black,
0 0 0 35px orange,
0 0 0 40px black,
0 0 0 45px teal,
0 0 0 50px black,
0 0 0 55px orange,
0 0 0 60px black,
0 0 0 65px teal,
0 0 0 70px black,
0 0 0 75px orange,
0 0 0 80px black,
0 0 0 85px teal;
}
html {
width: 100%;
height: 100%;
}
body {
background: #333333;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
box-sizing: border-box;
overflow: hidden;
}
.box {
box-shadow:
0 0 0 5px teal,
0 0 0 10px black,
0 0 0 15px orange,
0 0 0 20px black,
0 0 0 25px teal,
0 0 0 30px black,
0 0 0 35px orange,
0 0 0 40px black,
0 0 0 45px teal,
0 0 0 50px black,
0 0 0 55px orange,
0 0 0 60px black,
0 0 0 65px teal,
0 0 0 70px black,
0 0 0 75px orange,
0 0 0 80px black,
0 0 0 85px teal;
}
<div class="box"></div>
解决方案
linear-gradient
一个人做不到。你需要更多的属性。
这是我的想法clip-path
body {
background: #333333;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin:0;
}
.box {
width:225px;
background:repeating-linear-gradient(teal 0 5px,black 0 10px,orange 0 15px,black 0 20px);
}
.box:before {
content:"";
display:block;
padding-top:100%;
background:inherit;
clip-path:polygon(0 0,100% 0,0 100%,100% 100%);
transform:rotate(90deg);
}
<div class="box"></div>
也像下面:
body {
background: #333333;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin:0;
}
.box {
width:220px; /* adjust this value */
--coloration:teal 0 5px,black 0 10px,orange 0 15px,black 0 20px;
background:
repeating-linear-gradient(0deg, var(--coloration)) top,
repeating-linear-gradient(180deg,var(--coloration)) bottom;
background-size:100% 50%;
background-repeat:no-repeat;
}
.box:before {
content:"";
display:block;
padding-top:100%;
background:inherit;
clip-path:polygon(0 0,100% 0,0 100%,100% 100%);
transform:rotate(90deg);
}
<div class="box"></div>
推荐阅读
- c# - 字符串c#的地址变量
- javascript - 如何在 discord.js 中使用我自己的“say”命令向特定频道发送消息?
- python - 如何根据用户输入循环遍历字符串列表
- java - 有没有办法使用 Java 将 HTTPS GET 请求发送到带有访问令牌的 url?
- powerbi - 将 PowerBI 报告的自动电子邮件发送给个人或邮件列表
- google-sheets - 使用 Google 表格从 URL 中提取信息
- printing - 在打印操作中,有没有办法使用假脱机进程钩子获取启动打印的应用程序的名称/pid
- c# - 如何将多个gridviews导出到dot net中的单个pdf文件中
- python - 整数特征的 PMI 计算
- python - web3.py TX revert 不产生异常