前端 - webapp如果把页面div宽度设成100%,外边距设成5px,右边无法显示效果?
PHP中文网
PHP中文网 2017-04-17 11:31:49
0
6
652

我把整个ul的外边距设成4px,但只有右边的没反应。
在开发webapp时总遇到这种情况,距离只要和右边沾边就无法表现出来

PHP中文网
PHP中文网

认证0级讲师

reply all(6)
小葫芦
*{
   box-sizing: border-box;
}
黄舟

ul{box-sizing:border-box}

刘奇

You can use the two people upstairs box-sizing: border-box
You can also use {width: -moz-calc(100% - 8px); width: -webkit-calc(100% - 8px); width: calc(100% - 8px); margin: 0 4px;}

https://developer.mozilla.org/zh-CN/docs/Web/CSS/calc

Ty80

You are 100%+margin 5px*2>100%. Of course, it will not be displayed. Either add a box-sizing: border-box, or put a layer inside, remove the outer margins of the outer layer, and define padding of 5px on the inner layer. It is better.

洪涛

Border-box cannot control the margin, so you should be honest and not set the width of p to 100%, and then set the margin and it will be OK.

Ty80

I have encountered this before when I was working on an APP page for the first time. As mentioned above, remove 100% and set the margin directly.
In addition, in my impression, the border-box attribute only affects padding and border.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!