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

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

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

阅读 11.5k
5 个回答

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

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;

"

新手上路,请多包涵

高宽不变改变padding设置边框

有两种实现的方案,
第一种使用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 盒子阴影的内阴影,具体代码就不贴了,如果不懂的话就自己去学习吧。
如果题主是因为写了边框而造成了布局被撑坏,就需要去了解元素的盒子模型是怎么计算的了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题