CSS下標(biāo)怎么寫?
在CSS中,可以使用text-decoration
屬性來設(shè)置下標(biāo),可以通過text-decoration: underline;
來實(shí)現(xiàn)下劃線的樣式,給某個(gè)元素添加下標(biāo),可以像下面這樣寫:
.element { text-decoration: underline; }
.element
是要添加下標(biāo)的元素的選擇器,這樣,該元素就會(huì)顯示下劃線樣式的文本。
除了下劃線樣式,text-decoration
屬性還支持其他樣式,如下面這樣寫:
.element { text-decoration: line-through; /* 刪除線 */ }
或者這樣寫:
.element { text-decoration: overline; /* 上劃線 */ }
需要注意的是,text-decoration
屬性會(huì)應(yīng)用到所有文本,包括已經(jīng)設(shè)置過樣式的文本,如果只想給某個(gè)特定的文本添加下標(biāo),可以通過使用span
或a
等內(nèi)聯(lián)元素來實(shí)現(xiàn)。
<span class="underline">這是下標(biāo)文本</span>
或者這樣寫:
<a href="#" class="underline">這是下標(biāo)鏈接</a>
class="underline"
表示該元素應(yīng)用了上述的text-decoration: underline;
樣式,這樣,只有該特定的文本或鏈接會(huì)顯示下劃線樣式的文本。