Blogger Information
Blog 18
fans 0
comment 0
visits 14912
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
内边距padding
牛粪也香的博客
Original
982 people have browsed it

html:

调皮的内边距padding,会把DIV撑大
<div class="box1">
<img src="./static/img/bg.jpg" alt="背景" width="200px">
</div>
<br/>
用宽度分离:
<div class="wrap">

 <div class="box2">
 <img src="./static/img/bg.jpg" alt="背景" width="200px">
 </div>
</div>
<br/>
用box-sizing

<div class="box3">
<img src="./static/img/bg.jpg" alt="背景" width="200px">
</div>


css:

.box1{
 width: 500px;
 height: 200px;
 border: 1px solid red;
 background-color: black;
}
.box1{
 padding: 50px;
 width: 200px;
}
/*宽度分离*/
.wrap{
 width: 300px;
 /*height: 300px;*/
 border: 1px solid green;
 background-color: yellow;
}
.box2{
 background-color: white;
 border: 1px solid green;
 padding: 50px;
}

.box3{
 /*推荐使用*/
 box-sizing: border-box; /*这里一定要定位到border-box上,否则又会变大*/
 /*box-sizing: content-box; 这里一定要定位到border-box上*/
 width: 300px;
 background-color: pink;
 border: 1px solid red;
 padding: 50px;

}

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post