CSS Stands For Cascading Style Sheets.
CSS Stands For Cascading Style Sheets.
CSS Stands For Cascading Style Sheets.
CSS saves a lot of work. It can control the layout of multiple web
pages all at once.
Inline CSS
Example
<h1 style="color:blue;">This is a Blue Heading</h1>
Internal CSS
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: powderblue;
}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
External CSS
An external style sheet is used to define the style for many HTML
pages.
With an external style sheet, you can change the look of an entire
web site, by changing one file!
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet can be written in any text editor. The file
must not contain any HTML code, and must be saved with a .css
extension.
Example
p{
color: red;
text-align: center;
}
CSS Selectors
CSS selectors are used to "find" (or select) HTML elements based on
their element name, id, class, attribute, and more.
You can select all <p> elements on a page like this (in this case, all
<p> elements will be center-aligned, with a red text color):
Example
p{
text-align: center;
color: red;
}
The id Selector
The style rule below will be applied to the HTML element with
id="para1":
Example
#para1 {
text-align: center;
color: red;
}
The class Selector
Example
.center {
text-align: center;
color: red;
}
You can also specify that only specific HTML elements should be
affected by a class.
Example
p.center {
text-align: center;
color: red;
}
Example
<p class="center large">This paragraph refers to two classes.</p>
Grouping Selectors
If you have elements with the same style definitions, like this:
h1 {
text-align: center;
color: red;
}
h2 {
text-align: center;
color: red;
}
p{
text-align: center;
color: red;
}
In the example below we have grouped the selectors from the code
above:
Example
h1, h2, p {
text-align: center;
color: red;
}
CSS Comments
Comments are used to explain the code, and may help when you edit
the source code at a later date.
A CSS comment starts with /* and ends with */. Comments can also
span multiple lines:
Example
p{
color: red;
/* This is a single-line comment */
text-align: center;
}
/* This is
a multi-line
comment */