CSS Padding(填充)
CSS padding(填充)
CSS Padding(填充)屬性定義元素邊框與元素內(nèi)容之間的空間。
Padding(填充)
當(dāng)元素的 Padding(填充)(內(nèi)邊距)被清除時(shí),所"釋放"的區(qū)域?qū)?huì)受到元素背景顏色的填充。
單獨(dú)使用填充屬性可以改變上下左右的填充。縮寫填充屬性也可以使用,一旦改變一切都改變。
可能的值
值 | 說(shuō)明 |
---|---|
length | 定義一個(gè)固定的填充(像素, pt, em,等) |
% | 使用百分比值定義一個(gè)填充 |
填充- 單邊內(nèi)邊距屬性
在CSS中,它可以指定不同的側(cè)面不同的填充:
實(shí)例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> p { background-color:yellow; } p.padding { padding-top:25px; padding-bottom:25px; padding-right:50px; padding-left:50px; } </style> </head> <body> <p>This is a paragraph with no specified padding.</p> <p class="padding">This is a paragraph with specified paddings.</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
說(shuō)明:
上內(nèi)邊距是 25px
右內(nèi)邊距是 50px
下內(nèi)邊距是 25px
左內(nèi)邊距是 50px
填充 - 簡(jiǎn)寫屬性
為了縮短代碼,它可以在一個(gè)屬性中指定的所有填充屬性。
這就是所謂的縮寫屬性。所有的填充屬性的縮寫屬性是"padding":
實(shí)例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> p { background-color:yellow; } p.padding { padding:25px 50px; } </style> </head> <body> <p>This is a paragraph with no specified padding.</p> <p class="padding">This is a paragraph with specified paddings.</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
Padding屬性,可以有一到四個(gè)值。
padding:25px 50px 75px 100px;
上填充為25px
右填充為50px
下填充為75px
左填充為100px
padding:25px 50px 75px;
上填充為25px
左右填充為50px
下填充為75px
padding:25px 50px;
上下填充為25px
左右填充為50px
padding:25px;
所有的填充都是25px
更多實(shí)例
實(shí)例:在一個(gè)聲明中的所有填充屬性
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> p.ex1 {padding:2cm;} p.ex2 {padding:0.5cm 3cm;} </style> </head> <body> <p class="ex1">This text has equal padding on each side. The padding on each side is 2cm.</p> <p class="ex2">This text has a top and bottom padding of 0.5cm and a left and right padding of 3cm.</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
這個(gè)例子演示了使用縮寫屬性設(shè)置在一個(gè)聲明中的所有填充屬性,可以有一到四個(gè)值。
實(shí)例:設(shè)置左部填充
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> p.padding {padding-left:2cm;} p.padding2 {padding-left:50%;} </style> </head> <body> <p>This is a text with no left padding.</p> <p class="padding">This text has a left padding of 2 cm.</p> <p class="padding2">This text has a left padding of 50%.</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
這個(gè)例子演示了如何設(shè)置元素左填充。
實(shí)例:設(shè)置右部填充
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> p.padding {padding-right:2cm;} p.padding2 {padding-right:50%;} </style> </head> <body> <p>This is a text with no right padding. This is a text with no right padding. This is a text with no right padding.</p> <p class="padding">This text has a right padding of 2 cm. This text has a right padding of 2 cm. This text has a right padding of 2 cm.</p> <p class="padding2">This text has a right padding of 50%. This text has a right padding of 50%. This text has a right padding of 50%.</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
這個(gè)例子演示了如何設(shè)置元素右填充。
實(shí)例:設(shè)置上部填充
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> p.padding {padding-top:2cm;} p.padding2 {padding-top:50%;} </style> </head> <body> <p>This is a text with no top padding. This is a text with no top padding. This is a text with no top padding.</p> <p class="padding">This text has a top padding of 2 cm. This text has a top padding of 2 cm. This text has a top padding of 2 cm.</p> <p class="padding2">This text has a top padding of 50%. This text has a top padding of 50%. This text has a top padding of 50%.</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
這個(gè)例子演示了如何設(shè)置元素上填充。
實(shí)例:設(shè)置下部填充
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> p.padding {padding-bottom:2cm;} p.padding2 {padding-bottom:50%;} </style> </head> <body> <p>This is a text with no bottom padding. This is a text with no bottom padding. This is a text with no bottom padding.</p> <p class="padding">This text has a bottom padding of 2 cm. This text has a bottom padding of 2 cm. This text has a bottom padding of 2 cm.</p> <p class="padding2">This text has a bottom padding of 50%. This text has a bottom padding of 50%. This text has a bottom padding of 50%.</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
這個(gè)例子演示了如何設(shè)置元素下填充。
所有的CSS填充屬性
屬性 | 說(shuō)明 |
---|---|
padding | 使用縮寫屬性設(shè)置在一個(gè)聲明中的所有填充屬性 |
padding-bottom | 設(shè)置元素的底部填充 |
padding-left | 設(shè)置元素的左部填充 |
padding-right | 設(shè)置元素的右部填充 |
padding-top | 設(shè)置元素的頂部填充 |