Selecting Elements by Type
You can select all of the instances of an element by specifying the element type as the selector.
a
select all of the a
elements.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style type="text/css">
a {
border: thin black solid;
padding: 4px;
}
</style>
</head>
<body>
<a href="http://java2s.com">Visit the java2s.com</a>
<p>I like <span>HTML</span> and CSS.</p>
<a href="http://w3c.org">W3C website</a>
</body>
</html>
The following code applies a style to multiple element types by separating the types with a comma.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style type="text/css">
a,p {
border: thin black solid;
padding: 4px;
}
</style>
</head>
<body>
<a href="http://java2s.com">Visit the java2s.com</a>
<p>I like <span>HTML</span> and CSS.</p>
<a href="http://w3c.org">W3C website</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: