CSS实现多重边框

实现这样的效果 简单

Paste_Image.png
.box {
    width: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    background-color: lightskyblue;
    border: 20px solid royalblue;
}
<div class="box">
    box
</div>

但要实现这样的效果,不包裹div的前提下,使用outline属性

Paste_Image.png
.box {
    width: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    background-color: lightskyblue;
    border: 20px solid royalblue;
    outline: solid 20px brown;
}

但要实现这样的效果 outline 是不行的

Paste_Image.png

如果使用 outline 只会这样

.box {
    width: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    background-color: lightskyblue;
    border: 20px solid royalblue;
    border-radius: 30px;
    outline: solid 20px brown;
}
Paste_Image.png

但是用阴影 box-shadow 可以做到 就像这样

.box {
    width: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    background-color: lightskyblue;
    border: 20px solid royalblue;
    border-radius: 30px;
    box-shadow: 0 0 0 20px brown;
}
Paste_Image.png

还能这样

.box {
    width: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    background-color: lightskyblue;
    border: 20px solid royalblue;
    border-radius: 30px;
    box-shadow: 0 0 0 20px brown,
                0 0 0 40px salmon,
                0 0 0 60px crimson;
}
Paste_Image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 1,788评论 0 2
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,327评论 0 11
  • text-shadow是给文本添加阴影效果,box-shadow是给元素块添加周边阴影效果。随着HTML5和CSS...
    arlene112阅读 2,280评论 0 1
  • 1、垂直对齐 如果你用CSS,则你会有困惑:我该怎么垂直对齐容器中的元素?现在,利用CSS3的Transform,...
    kiddings阅读 3,195评论 0 11
  • 不知道我从哪里看到了这样一篇文章,它讲的是一个家境 虽然贫穷但拥有高尚品德的孩子故事。 在一个偏僻的小山村的附近,...
    闫怡璇阅读 271评论 0 0