Smartguide CSS
Smartguide CSS
for
CSS
Concise guidelines for beginners
Compiled by
NuBari, LE
[email protected]
CONTENTS
CONTENTS .......................................................................................................... 1
START HERE......................................................................................................... 2
WHAT IS CSS? ........................................................................................................ 2
HOW TO ADD CSS TO HTML ................................................................................ 2
THREE (3) WAYS TO ADD CSS: ...................................................................................... 2
INLINE CSS ............................................................................................................. 2
INTERNAL CSS ........................................................................................................ 3
EXTERNAL CSS ........................................................................................................ 4
CSS COLORS, FONTS AND SIZES................................................................................... 5
CSS BORDER .......................................................................................................... 5
LINK TO EXTERNAL CSS ............................................................................................. 6
The most common way to add CSS, is to keep the styles in external CSS files.
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.
The following example sets the text color of the <h1> element to blue, and the
text color of the <p> element to red:
<body style="color:green;">
<p>Every texts and items placed within this body shall be green in color.</p>
<h1>Even this heading text shall appear green</h1>
<p style="color:red;"> My school bag is red in color.</p>
</body>
Note: the cascading rule uses the inline css applied to the last paragraph tag within the
body tag to take a red colour different from the green colour already applied to the
body.
Internal CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within a
<style> element.
The following example sets the text color of ALL the <h1> elements (on that
page) to blue, and the text color of ALL the <p> elements to red. In addition, the
page will be displayed with a "orange" background color:
Example
<!DOCTYPE html>
<html>
<head>
<title>My Css demo page</title>
<style>
body {background-color: orange;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Copy the below styles into a text file and save it as "styles.css" file looks like:
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p{
color: red;
}
Tip: With an external style sheet, you can change the look of an entire web site, by
changing one file!
Example
Use of CSS color, font-family and font-size properties:
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p{
color: red;
font-family: courier;
font-size: 160%;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Border
The CSS border property defines a border around an HTML element.
Tip: You can define a border for nearly all HTML elements.
p{
border: 2px solid powderblue;
}
CSS Padding
The CSS padding property defines a padding (space) between the text and the border.
Example
Use of CSS border and padding properties:
p{
border: 2px solid powderblue;
padding: 30px;
}
CSS Margin
The CSS margin property defines a margin (space) outside the border.
Example
Use of CSS border and margin properties:
p{
border: 2px solid powderblue;
margin: 50px;
}
Example
This example uses a full URL to link to a style sheet:
Example
This example links to a style sheet located in the html folder on the current web site: