Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
What is CSS?
Cascading Style sheets (CSS) is a language that works with HTML documents to define the way how web pages are
presented.
Presenting a document to a user means converting it into a useable form for your audience.
A brief History of CSS:
External style sheet are ideal when the style is applied to many pages.
With external style sheets, you can change the look of an entire web site by changing one file.
External styles are defined in an external CSS file, and then linked to in the <head> section of
an HTML page:
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>
Internal Styling or Embedding CSS
An internal style sheet can be used to define a common style for all HTML elements on a page.
Internal styling is defined in the <head> section of an HTML page, using a <style> element:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Internal Styling</title>
Internal Styling or Embedding CSS
<style>
body{background-color:#9F6;}
h1{color:blue}
p{color:green}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Inline Styling (Inline CSS)
An inline style may be used to apply a unique style for a single element.
An inline style loses many of the advantages of a style sheet (by mixing content with
presentation). Use this method sparingly!
To use inline styles, add the style attribute to the relevant tag. The style attribute can
contain any CSS property. The example shows how to change the color and the left
margin of a <h1> element:
Inline Styling (Inline CSS)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<h1 style="color:blue">This is a Blue Heading</h1>
</body>
</html>
Multiple Style Sheets
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Multiple Style Sheets</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
body {background-color: linen;}
</style>
</head>
Multiple Style Sheets
</body>
</html>