凑和着用吧,哈哈
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
body {
background-color: black;
}
.wrap {
border: 2px solid orange;
border-radius: 4px;
position: relative;
width: 200px;
height: 100px;
padding: 8px;
}
.wrap__cover1 {
position: absolute;
top: -2px;
bottom: -2px;
width: 140px;
background: black;
left: calc(50% - 70px);
}
.wrap__cover2 {
position: absolute;
left: -2px;
right: -2px;
height: 40px;
background: black;
top: calc(50% - 20px);
}
.wrap__content {
border: 1px solid orange;
border-radius: 4px;
width: 100%;
height: 100%;
position: relative;
z-index: 100px;
}
</style>
<body>
<div class="wrap">
<div class="wrap__cover1"></div>
<div class="wrap__cover2"></div>
<div class="wrap__content"></div>
</div>
</body>
</html>
配合伪元素,可以不添加额外的元素添加四角外框,不过没法实现圆角。
代码:
<style>
div{
margin: 40px;
border: solid 1px #2f89de;
border-radius: 6px;
height: 160px;
width: 300px;
position: relative;/*元素必须有定位,以方便伪元素相对于此元素定位*/
}
div:before,
div::before{
border-radius: 6px;
content: '';
position: absolute;/*必须使用绝对定位*/
top: -36px;
right: -36px;
bottom: -36px;
left: -36px;
background: linear-gradient(to left, #196aa8, #196aa8) left top no-repeat,
linear-gradient(to bottom, #196aa8, #196aa8) left top no-repeat,
linear-gradient(to left, #196aa8, #196aa8) right top no-repeat,
linear-gradient(to bottom, #196aa8, #196aa8) right top no-repeat,
linear-gradient(to left, #196aa8, #196aa8) left bottom no-repeat,
linear-gradient(to bottom, #196aa8, #196aa8) left bottom no-repeat,
linear-gradient(to left, #196aa8, #196AA8) right bottom no-repeat,
linear-gradient(to left, #196aa8, #196aa8) right bottom no-repeat;
background-size: 4px 36px, 36px 4px, 4px 36px, 36px 4px;
}
</style>
<div></div>
——————————————————————————
Refrence: CSDN「李晓怡」:css 四角边框;
13 回答12.6k 阅读
2 回答4.9k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
7 回答2k 阅读
3 回答2.1k 阅读
5 回答535 阅读
3 回答1.2k 阅读✓ 已解决
css 实现矩形四个边角加粗的方法 参考这篇文章,稍加修改,实现效果如下:

css 实现矩形四个边角加小外框
代码如下: