padding 簡寫屬性在一個聲明中設置所有內邊距屬性。
說明:
這個簡寫屬性設置元素所有內邊距的寬度,或者設置各邊上內邊距的寬度。行內非替換元素上設置的內邊距不會影響行高計算;因此,如果一個元素既有內邊距又有背景,從視覺上看可能會延伸到其他行,有可能還會與其他內容重疊。元素的背景會延伸穿過內邊距。不允許指定負邊距值。
注釋:不允許使用負值。
---------摘自http://www.w3school.com.cn/css/pr_padding.asp--------
如下代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xms="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style> div { width:200px; height:200px; border:1px dashed #ccc; margin:10px auto; } .div1 { padding:-30px; } .div2 { padding:30px; } </style> </head> <body> <div class="div1"> <p>padding 不能為負 </p> <p>padding:-30px; </p> </div> <div class="div"> <p>padding 不能為負 </p> <p>不設置padding</p> </div> <div class="div2"> <p>padding 不能為負 </p> <p>padding:30px;</p> </div> </body> </html>
運行結果:
第一個 (padding:-30px;)和第二個(沒有設定padding)顯示的效果是一樣的。也就是說設定負值的padding是沒有意義的。w3cschool指出:不允許使用負值。