W3schools - HTML_Class / Id
찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요
ID
Is used to specify a unique id for an HTML element
The value of the id attribute must be unique within the HTML document
Is used to point to a specific style declaration in a style sheet
Is used by JS to access and manipulate the element with the specific id
CSS Syntax : #IdName{…}
Id name is case sensitive, it must contain at least one character, can’t start with number, and must not contain whitespace
HTML bookmarks with Id and links
<h2 id="”C4”">Chapter 4</h2>
/* Add a link to the bookmark, from within the same page */
<a href="”#C4”">Jump to Chapter 4</a>
/* from another page */
<a herf="”html_demo.html#C4”"> Jump to Chapter 4</a>
Class
Is used to specify a class for an HTML element
Multiple HTML elements can share the same class
Is often used to point to a class name in a style sheet
Can also be used by a JavaScript to access and manipulate elements with the specific class name
Can be used on any HTML element, and is case sensitive
CSS Syntax : .className{…}
Different elements cans share same class
Multiple classes
-
HTML elements can belong to more than one class
-
To define multiple classes, separate the class names with a space
-
The element will be styled according to all the classes specified
<div class="”main" sub”></div>