Preface This article introduces how to use the new CSS3 attribute box-sizing to solve the problem of setting the div width to 100% and then setting padding or margin beyond the parent element. Friends in need can refer to it. grammar box-sizing: content-box|border-box|inherit; Value 1, content-box This is the width and height behavior specified by CSS2.1. The width and height are applied to the element's content box respectively. The element's padding and border are drawn in addition to the width and height. Value 2, border-box The width and height specified for an element determine the element's border box. That is, any padding and borders specified for the element will be drawn within the specified width and height. The content width and height are obtained by subtracting the border and padding from the set width and height respectively. Value 3: inherit Specifies that the value of the box-sizing property should be inherited from the parent element. example <!DOCTYPE html> <html> <head> <style> div.container { width:100%; border:1em solid; padding:15px; box-sizing:border-box; } div.box { box-sizing:border-box; -moz-box-sizing:border-box; /* Firefox */ -webkit-box-sizing:border-box; /* Safari */ width:100%; border:1em solid red; float:left; padding:15px; } </style> </head> <body> <div class="container"> <div class="box">This div occupies the left half. </div> </div> </body> </html> Summarize The above is the full content of this article. I hope that the content of this article can be of some help to your study or work. If you have any questions, you can leave a message to communicate. |
<<: Node+Express test server performance
Table of contents Common payment methods in proje...
Table of contents 1. Use SVG 2. Use fontAwesome 3...
Table of contents Install CentOS7 Configuring Sta...
One trick for dealing with this type of error is t...
1. Import the basic style of external CSS files U...
Table of contents Preface Scope 1. What is scope?...
This article introduces the flex layout to achiev...
Three types of message boxes can be created in Ja...
Provide login and obtain user information data in...
Table of contents 1. Simple page example 2.uni-ap...
Arrange by functionNN : Indicates which earlier ve...
MySQL is now the database used by most companies ...
This article mainly introduces the analysis of th...
Table of contents environment: 1. Docker enables ...
A few days ago, I saw an example written by @Kyle...