首页 > css 使用 边框 border 的时候,怎么让他作为内边框。

css 使用 边框 border 的时候,怎么让他作为内边框。

.bk{
border-style:solid;
border-width:10px;
border-color:red;
}

这个,怎么让他朝内?就是不改变宽度高度?


高宽不变改变padding设置边框


box-sizing:border-box;IE8下不支持


有两种实现的方案,
第一种使用css 伪类

    .bk{
        position: relative;
        width:100px;
        height:100px;
    }
    .bk:before{
        content:"";
        position: absolute;
        top:0;
        left:0;
        width:98px;
        height:98px;
        border:1px solid #666;
    }

第二种使用 box-shadow 盒子阴影的内阴影,具体代码就不贴了,如果不懂的话就自己去学习吧。
如果题主是因为写了边框而造成了布局被撑坏,就需要去了解元素的盒子模型是怎么计算的了。


box-sizing:border-box;


没有css属性可以直接做成你想要的那种效果哦,你只能模拟哈

style="

border-bottom: 50px solid red;
border-top: 50px solid blue;
border-left: 50px solid white;
border-right: 50px solid black;
height: 0;
width: 0;

"

【热门文章】
【热门文章】