CSS Selectors | css id選擇器
ACSSselectorselectstheHTMLelement(s)youwanttostyle.CSSSelectorsCSSselectorsareusedto"find"(orselect)theHTMLelementsyouwanttostyle.WecandivideCSSselectorsintofivecategories:ThispagewillexplainthemostbasicCSSselectors.TheCSSelementSelectorTheelementselectorselectsHTMLelementsbasedontheelementname.ExampleHere,all
elementsonthepagewillbecenter-aligned,witharedtextcolor: p{ text-align:center; color:red;}TryitYourself»[1]TheCSSidSelectorTheidselectorusestheidattributeofanHTMLelementtosel...
A CSS selector selects the HTML element(s) you want to style.
CSS SelectorsCSS selectors are used to "find" (or select) the HTML elements you want to style.
We can divide CSS selectors into five categories:
This page will explain the most basic CSS selectors.
The CSS element SelectorThe element selector selects HTML elements based on the element name.
ExampleHere, all <p> elements on the page will be center-aligned, with a red text color:
p { text-align: center; color: red;}
Try it Yourself »[1] The CSS id SelectorThe id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one unique element!
To select an element with a specific id, write a hash (#) character, followed by the id of the element.
ExampleThe CSS rule below will be applied to the HTML element w...