7.HTML CSS
7.HTML CSS
CSS saves a lot of work. It can control the layout of multiple web pages all at
once.
CSS Syntax :
A CSS rule-set consists of a selector and a declaration block:
A CSS declaration always ends with a semicolon, and declaration blocks are
surrounded by curly braces
CSS can be added to HTML elements in 3 ways:
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
<h1 style="color:blue;">This is a Blue Heading</h1>
Internal CSS
An internal CSS is used to define a style for a single HTML page.
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
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!
To use an external style sheet, add a link to it in the <head> section of the
HTML page
The id Selector :
The id selector uses the id attribute of an HTML element to select a specific
element.
To select an element with a specific id, write a hash (#) character, followed by
the id of the element.
#test {
text-align: center;
color: red;
}
To select elements with a specific class, write a period (.) character, followed by
the name of the class.
In the example below, all HTML elements with class="test" will be red and
center-aligned:
.test {
text-align: center;
color: red;
}
Grouping Selectors
If you have elements with the same style definitions
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.
CSS background:
Background Color
The background-color property specifies the background color of an element.
body {
background-color: lightblue;
}
Background Image
The background-image property specifies an image to use as the background of
an element.
body {
background-image: url("paper.gif");
}
CSS Fonts :
The CSS color property defines the text color to be used.
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}
CSS Border :
The CSS border property defines a border around an HTML element.
p {
border: 1px solid red;
}
CSS Padding
The CSS padding property defines a padding (space) between the text and the
border:
p {
border: 1px solid powderblue;
padding: 30px;
}
CSS Margin:
p {
border: 1px solid powderblue;
margin: 50px;
}