Css Class & ID: - by Rupam Patel (MCA)
Css Class & ID: - by Rupam Patel (MCA)
</head>
Example
CSS HTML class Create a class named "city":
<!DOCTYPE html>
<html>
Tip: The class attribute can be used on any HTML
<head>
element.
<style>
Note: The class name is case sensitive! .city {
background-color: tomato;
color: white;
The Syntax For Class padding: 10px;
}
To create a class; write a period (.) character, </style>
followed by a class name. Then, define the CSS </head>
properties within curly braces {}: <body>
<h2 class="city">London</h2>
<p>London is the capital of England.</p>
<h2 class="city">Paris</h2>
<p>Paris is the capital of France.</p>
<h2 class="city">Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>
</body>
</html>
Multiple Classes Different Elements Can
Share Same Class
HTML elements can belong to more than one class.
Different HTML elements can point to the same
class name.
To define multiple classes, separate the class names
with a space, e.g. <div class="city main">. The
In the following example, both <h2> and <p> points
element will be styled according to all the classes
to the "city" class and will share the same style:
specified.
<h2 class="city">Paris</h2>
In the following example, the first <h2> element
belongs to both the city class and also to the main
<p class="city">Paris is the capital of
class, and will get the CSS styles from both of the France</p>
classes:
Example
<h2 class="city main">London</h2>
<h2 class="city">Paris</h2>
<h2 class="city">Tokyo</h2>
HTML id Attribute Using The id Attribute
The id attribute specifies a unique id for an HTML
element. The value of the id attribute must be
The HTML id attribute is used to specify a unique unique within the HTML document.
id for an HTML element.
The id attribute is used to point to a specific style
You cannot have more than one element with the declaration in a style sheet. It is also used by
same id in an HTML document. JavaScript to access and manipulate the element
with the specific id.
</body>
</html>
/* Style all elements with the class name
Class and ID
.city {
background-color: tomato;
color: white;
Bookmarks can be useful if your page is very long. Or, add a link to the bookmark ("Jump to Chapter
4"), from another page:
To use a bookmark, you must first create it, and
then add a link to it. <a href="html_demo.html#C4">Jump to Chapter
4</a>
Then, when the link is clicked, the page will scroll to
the location with the bookmark.