Selecting Elements by ID
The ID selector selects elements by the global id attribute.
Syntax:
#idvalue
or
elementType.#idvalue
The value of an element's id attribute must(should) be unique within the HTML document.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style type="text/css">
#myAnchor {
border: thin black solid;
padding: 4px;
}
</style>
</head>
<body>
<a id="myAnchor" href="http://java2s.com"> Visit the java2s.com </a>
</body>
</html>
Home
HTML CSS Book
CSS
HTML CSS Book
CSS
Selectors:
- Selecting All Elements
- Selecting Elements by Type
- Selecting Elements by Class
- Selecting Elements by ID
- Selecting Elements by Attribute
Related: