Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the difference between width:100%; and width:auto; in CSS

Shulou Source: shulou.com Published: 2022-06-03 14:40:30 11月14日 Update

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!

Tags: Content width article not much region most that is overall more knowledge space industry information information channel or channel reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno macOS Xiaomi Shulou Tech Info NVidia