html - CSS中的装饰艺术风格边框
解决方案
你可以这样做:
.box {
width:150px;
height:200px;
border:15px solid transparent; /* control the offset of the lines */
outline:2px solid #000; /* adjust the 2px here */
outline-offset:-10px; /* control the offset of the rectangle */
background:
linear-gradient(#000 0 0) top,
linear-gradient(#000 0 0) left,
linear-gradient(#000 0 0) bottom,
linear-gradient(#000 0 0) right;
background-size:200% 2px,2px 200%; /* adjust the 2px here */
background-origin:padding-box;
background-repeat:no-repeat;
}
<div class="box"></div>
使用 CSS 变量轻松控制:
.box {
--c:red; /* color */
--b:2px; /* thickness of lines */
--o1:15px; /* offest of lines*/
--o2:10px; /* offset of rectangle */
width:150px;
height:200px;
box-sizing:border-box;
display:inline-block;
border:var(--o1) solid transparent;
outline:var(--b) solid var(--c);
outline-offset:calc(-1*var(--o2));
background:
linear-gradient(var(--c) 0 0) top,
linear-gradient(var(--c) 0 0) left,
linear-gradient(var(--c) 0 0) bottom,
linear-gradient(var(--c) 0 0) right;
background-size:200% var(--b),var(--b) 200%;
background-origin:padding-box;
background-repeat:no-repeat;
}
<div class="box"></div>
<div class="box" style="--c:green;--b:1px;--o1:20px;"></div>
<div class="box" style="--c:blue;--b:4px;--o1:40px;--o2:20px;"></div>
<div class="box" style="--c:#000;--b:1px;--o1:10px;--o2:0;"></div>
推荐阅读
- javascript - Amcharts V4如何修复CategoryAxis的值?
- javascript - GitHub 没有读取 JSON 文件
- javascript - Next.js gow 获取数据并将其传递给自定义 App 环境中的 react dom
- regex - 什么是正则表达式模式“带有数字的单词”,而不是数字本身
- node.js - Firebase 存储 - 将文件的内容作为字符串获取
- google-apps-script - 用于制作超链接的 Google 脚本(用于按钮)
- sql-server - 不同长度的 SQL SUBSTRING & PATINDEX
- haskell - 如何在haskell的列表中查找列表的长度?
- python - 如何使用 asn1tools 解码 asn1 十六进制值
- r - 有条件地改变顶点形状