Divs, Spans, Ids, and Classes - Comm 244
文章推薦指數: 80 %
The div tag is a block level HTML element. It is used to divide or section of other HTML tags in to meaningful groups. A perfect example of the use of a div tag ... BacktoClassThreepage» Divs,Spans,Id's,andClasses TheHTMLtagsdivandspanholdnopresentationalvaluebythemselves.ThismeansthatifyouputtheninyourHTML,theywillnotactuallydisplayanything. Thesetagsareprimarilyusedas"hooks"foryourCSS.YouusethemtodivideorlabelyourHTML(whenanother,moresemantictagwillnotwork)anduseCSSselectorstotargetthem. ClassandId'sareHTMLAttributes.TheyarealsousedasCSShooks. BlockversusInlineHTMLElements FromStylin'WithCSSbyCharlesWyke-Smith: ...mostXHTMLtagsfallintotwobroadcategoriesinrespecttothewaytheydisplayonthepage:blockandinline.Blocklevelelementssuchasheadings
throughandparagraphs
willobliginglystackdownthepagewithnolinebreaksrequired.Theyevenhavepresetmarginstocreatespacebetweenthem.Inlineelementshavenosuchmargins,andsitsidebysideacrossthepage,onlywrappingtothenextlineifthereisnotenoughroomforthemtositnexttoeachother.(p.18)
DivTag
ThedivtagisablocklevelHTMLelement.ItisusedtodivideorsectionofotherHTMLtagsintomeaningfulgroups.
Aperfectexampleoftheuseofadivtagistodesignateanavigationlist:
sidebartextLoremipsumdolorsitamet,consecteturadipisicingelit.
SpanTag
ThespantagisaninlineHTMLelementthatisusedtogroupasetofinlineelements.Generallyspeaking,youusespantohooktextoragroupoftagsthatyouwanttostyledifferently.Oftenthough,youcandothismoresemanticallybyusingotherelementslikeemorstrong.
Agoodexampleofanappropriateuseofspanisinaheaderthatyouwanttostyleintwoparts.
Comm244:DesignfortheWWW
IdAttribute
TheidattributeisusedtolabelsectionsorpartsofyourHTMLdocument.
Youmayonlyusethesameidonceperpage,sosaveitforimportantmajorsectionsofyourpage.Additionally,theidselectorinCSShasahighspecificitylevelandthereforeoverrulesotherthings(liketheclassselector).
ClassAttribute
Ifapagehadmultiplesidebarchunks,wemightwanttomakeoneclasssothatwecoulduseCSStostyleeachchunkwithonerule.
SidebarTitle
延伸文章資訊
- 1Q. What is the difference between div and class? - Stack Overflow
- 2HTML div tag - W3Schools
- 3What is the Difference Between div id and div class - Pediaa.Com
- 4HTML div tag - W3Schools
The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a con...
- 5切版與前端框架最常使用的CSS選取器 - iT 邦幫忙
class的規則. CSS class 在HTML 原始碼中的長相就像下方這樣 <div class="amos">文字內容</div>.