What is the difference between width:100%; and width:auto; in CSS
Editor to share with you what is the difference between width:100%; and width:auto; in CSS, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1111
Div {width:980px
Background-color: # ccc
Height:300px;} p {width:100%
/ * width:auto;*/ padding:10px
Background-color:#000
}
If it is the width:100%, of p, it means that the width of p will get 980px, which is already full of div area, and then has its own padding, so it will exceed the div.
When width:auto, it is the overall width (including width,margin,padding,border) equal to the parent width (width, does not include the parent margin,padding,border), so if the padding has taken up the space of the 10px, then the value given by width is 960px.
However, whether it is width:100% or auto, the calculation reference is the parent content area width value, not the total width value.
The above is all the content of the article "what is the difference between width:100%; and width:auto; in CSS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!