id selector
The
id selector is introduced using "#", which has the same effect as the "." of the class selector. Example: #div{} Let's do a specific experiment: html:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>認(rèn)識html標(biāo)簽</title> <style type="text/css"> </style> </head> <body> <h1>勇氣</h1> <p>三年級時(shí),我還是一個(gè)<span id="stress">膽小如鼠</span>的小女孩,上課從來不敢回答老師提出的問題,生怕回答錯(cuò)了老師會(huì)批評我。就一直沒有這個(gè)勇氣來回答老師提出的問題。學(xué)校舉辦的活動(dòng)我也沒勇氣參加。</p> <p>到了三年級下學(xué)期時(shí),我們班上了一節(jié)公開課,老師提出了一個(gè)很簡單的問題,班里很多同學(xué)都舉手了,甚至成績比我差很多的,也舉手了,還說著:"我來,我來。"我環(huán)顧了四周,就我沒有舉手。</p> </body> </html>
css:
#stress{ color:red; }
Rendering:
In many ways, ID selectors are similar to class selectors, but There are also some important differences:
1. Set id="ID name" for the label instead of class="class name".
2. The ID selector is preceded by a pound sign (#) instead of an English dot (.).