width:100%;與width:auto的使用區別

來源:互聯網
上載者:User
這次給大家帶來width:100%;與width:auto的使用區別,使用width:100%;與width:auto的注意事項有哪些,下面就是實戰案例,一起來看一下。

<p>    <p>1111</p></p>p{  width:980px;<br>  background-color: #ccc;<br>  height:300px;}p{     width:100%;<br>  /*width:auto;*/    padding:10px;<br>  background-color:#000;<br>}

如果是p的width:100%,則說明p的width會得到980px就已經充滿p地區,然後自己又有padding,所以會超出p。

而當width:auto時它是總體寬度(包括width,margin,padding,border)等於父級寬度(width,不包含父級的margin,padding,border),所以如果padding已經左右佔去10px的空間,那麼width給的值就是960px。

但無論是width:100%還是auto,其計算的參照都是父級內容區width值,而非總寬度值.

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

瀑布流布局與無限載入圖片相簿效果

CSS實現3D按鈕效果

用transparent做出三角形

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.