CSS Intro
CSS Intro
Here, all <p> elements on the page will be center-aligned, with a red
text color:
p{
text-align: center;
color: red;
}
Class Selector/ Stylesheet ‘Class’:
Selects HTML elements with a specific class attribute.
Allows us to define multiple styles for the same type of HTML element.
.
It is used with a period character ‘ ’ followed by the class name.
Syntax 1:
selector.classname{
property1 :valuel;
property2 : value;
….
}
Example:
<p> elements with class="center" will be red and center-aligned:
CSS Rule:
p.center {
text-align: center;
color: red;
}
Id Selector:
Uses the id attribute of an HTML element to select a specific element.
There should be only one element with a given ID in a document.
Syntax:
#idname{
property1 :valuel;
property2 : value;
…..
}
Example:
The CSS rule below will be applied to the HTML element with id="para1":
CSS rule: #para1 {
text-align: center;
color: red;
}
HTML Code:<p id="para1"> This Paragraph is Red in color </p>
Grouping Selector:
Used when we want to apply same styles to multiple elements.
The grouping selector selects all the HTML elements with the same style definitions.
To group selectors, each selector is separated by a space.
Syntax: