<!DOCTYPE html>
<html>
<head></head>
<body>
<h1 style="color: navy;">Title</h1>
<h2 style="color: grey;">Subtitle</h2>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
h1 {
font-size: 1.2em;
color: navy;
}
h2 {
font-size: 0.9em;
color: grey;
}
</style>
</head>
<body>
<h1>Title</h1>
<h2>Subtitle</h2>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="style.css">
</head>
<body>
<h1>Title</h1>
<h2>Subtitle</h2>
</body>
</html>
h1 {
font-size: 1.2em;
color: navy;
}
h2 {
font-size: 0.9em;
color: grey;
}
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@import url("style.css");
</style>
</head>
<body>
<h1>Title</h1>
<h2>Subtitle</h2>
</body>
</html>
h1 {
font-size: 1.2em;
color: navy;
}
h2 {
font-size: 0.9em;
color: grey;
}
l'uso del tag style è la soluzione adatta solo per:
l'inclusione di file css esterni alla pagina (attraverso il tag link e la direttiva @import del css):
<!DOCTYPE html>
<html>
<head>
<title>Test Selector</title>
<link href="08_selectors_by_tagname.css"
rel="stylesheet" type="text/css"/>
</head>
<body>
<h1>title</h1>
<p>text paragram</p>
</body>
</html>
p { background: yellow; }
h1 { color: red; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selector</title>
<link href="08_selectors_by_id.css"
rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="nav">
<h1 id="brand">Brand</h1>
<p>paragram</p>
</div>
</body>
</html>
div#nav { background: grey; }
#brand { color: white; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selector</title>
<link href="08_selectors_by_class.css"
rel="stylesheet" type="text/css"/>
</head>
<body>
<p class="warning">warning paragram</p>
<p class="error">error paragram</p>
<p class="nav-item active">active menu</p>
</body>
</html>
.warning { background: orange; }
.error {background: red; }
.nav-item.active { color: blue; font-size: 1.2em; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selector</title>
<link href="08_selectors_grouping.css"
rel="stylesheet" type="text/css"/>
</head>
<body>
<h1>Header Level1</h1>
<h2>Header Level2</h2>
<h3>Header Level3</h3>
<hr>
<h4>Header Level4</h4>
<h5>Header Level5</h5>
<h6>Header Level6</h6>
</body>
</html>
h1, h2, h3 { color: navy; }
h4, h5, h6 { color: grey; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selector</title>
<link rel="stylesheet" type="text/css"
href="08_selectors_descendants.css" />
</head>
<body>
<nav>
<h1>Site Name</h1>
</nav>
<section>
<article>
<header>
<h1>Article Title</h1>
</header>
<p>Article Content</p>
</article>
</section>
</body>
</html>
nav h1 { color: navy; }
article h1 { color: grey; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selector</title>
<link rel="stylesheet" type="text/css"
href="08_selectors_childs.css" />
</head>
<body>
<header>
<h1>Site Name</h1>
</header>
<section>
<article>
<header>
<h1>Article Title</h1>
</header>
<p>Article Content</p>
</article>
</section>
</body>
</html>
body > header > h1 { color: navy; }
article > header > h1 { color: grey; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selector</title>
<link rel="stylesheet" type="text/css"
href="08_selectors_universal.css" />
</head>
<body>
<nav>
<h1>Site Name</h1>
</nav>
<section>
<article>
<header>
<h1>Article Title</h1>
</header>
<p>Article Content</p>
</article>
</section>
</body>
</html>
* { color: navy; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selector</title>
<link rel="stylesheet" type="text/css"
href="08_selectors_siblings.css" />
</head>
<body>
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
<hr>
<header>
<h1>Title</h1>
<h2>Subtitle</h2>
</header>
<hr>
<header>
<h2>Subtitle</h2>
</header>
</body>
</html>
li + li { color: red; }
h1 + h2 { color: lightgrey; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selectors</title>
<link rel="stylesheet"
href="08_selectors_by_attr.css" />
</head>
<body>
<ul lang="en">
<li>
<a data-urltype="work personal email" href="mailto:luca.greco@alcacoop.it">Mail me</a>
</li>
<li>
<a data-urltype="work website" href="http://alcacoop.it">Web Site</a>
</li>
</ul>
</body>
</html>
ul[lang] { color: white; }
ul[lang=en] { background: lightblue; }
a[data-urltype~=work] { background: lightgrey; }
a[data-urltype~=personal] { color: white; }
<!DOCTYPE html>
<html>
<head>
<title>Test Selectors</title>
<link rel="stylesheet"
href="08_selectors_pseudo.css" />
</head>
<body>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</body>
</html>
/* pseudo-class */
li:hover { background: yellow; color: green; }
li:last-child { font-style: italic; }
/* pseudo-element */
li:first-letter { font-size : 2.5em ; }
li:after { content: ";"; }
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="09_text_font.css" />
</head>
<body>
<h1>Header Level1</h1>
<h2>Header Level2</h2>
<h3>Header Level3</h3>
</body>
</html>
/* text properties */
h1 {
/* red, #ff0000 */
color: rgb(255, 0, 0);
/* normal */
word-spacing: 15px;
}
h2 {
/* normal */
letter-spacing: 15px;
/* left, right */
text-align: center;
}
h3 {
text-indent: -10px;
text-indent: 15%;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="09_text_font2.css" />
</head>
<body>
<h1>Header Level1</h1>
<h2>Header Level2</h2>
</body>
</html>
/* text properties */
h1 {
/* none, underline, overline */
text-decoration: line-through;
}
h2 {
/* none, lowercase, capitalize */
text-transform: uppercase;
}
<!DOCTYPE html>
<html>
<head>
<style rel="stylesheet" type="text/css">
p {
white-space: pre;
}
</style>
</head>
<body>
<p>
...The Poem problem...
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
p.serif {
font-family: "Times New Roman", Times, serif;
font-size: 1.2em;
}
p.sansserif {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
</style>
</head>
<body>
<h1>CSS font-family</h1>
<p class="serif">paragrafo con font Times New Roman.</p>
<p class="sansserif">paragrafo con font Arial.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div.box {
width: 220px;
padding: 10px;
border:5px solid gray;
margin:0px;
}
div.box-sizing {
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 220px;
padding: 10px;
border:5px solid lightgreen;
margin:0px;
}
</style>
</head>
<body>
<h2>Margin</h2>
<div class="box">
box width 220 + padding 10 + border 5 + margin 0:<br />
la larghezza totale dell'elemento sarà 250px.
</div>
<div class="box-sizing">
box width 220 + padding 10 + border 5 + margin 0:<br />
la larghezza totale dell'elemento sarà 220px.
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
p.padding {padding-left:2cm;}
p.padding2 {padding-left:50%;}
</style>
</head>
<body>
<h2>Padding</h2>
<p>Testo senza padding</p>
<p class="padding">Padding in cm</p>
<p class="padding2">Padding in percentuale</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
h2.pos_left {
position: relative;
left: -20px;
}
h2.pos_right {
position:relative;
left:20px;
}
</style>
</head>
<body>
<h1>Posizionamento Relativo</h1>
<h2>nessun cambiamento alla positione</h2>
<h2 class="pos_left">posizione spostata a sinistra</h2>
<h2 class="pos_right">posizione spostata a destra</h2>
<p>Il posizionamento relativo sposta un elemento relativamente alla sua posizione originale.</p>
<p>Con "left: -20px" spostiamo l'elemento di 20 pixels a sinistra rispetto alla posizione originale dell'elemento.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
p.pos_fixed {
position:fixed;
top:30px;
right:5px;
}
</style>
</head>
<body>
<h1>Fixed positioning</h1>
<p class="pos_fixed">Some more text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
p.pos_absolute {
position: absolute;
top: 30px;
right: 5px;
}
</style>
</head>
<body>
<h1>Posizionamente Assoluto</h1>
<p class="pos_absolute">Some more text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
<p>Some text</p><p>Some text</p>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
.external {
position: relative;
width: 600px;
height: 400px;
background-color: blue;
}
.internal {
position: absolute;
bottom: 0px;
width: 200px;
background-color: red;
}
</style>
</head>
<body>
<h1>Posizionamento misto relativo + assoluto</h1>
<div class="external">
<div class="internal">
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
</div>
</div>
</html>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="09_layouting.css">
</head>
<body>
<div id="page-wrap">
<header><h1>Header</h1></header>
<nav>
<ul>
<li>
<a href="#">Home</a>
<a href="#">Section1</a>
<a href="#">Section2</a>
</li>
</ul>
</nav>
<article id="content">
<header><h1>Content</h1></header>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi, dolor, ratione, id incidunt sed obcaecati dolores assumenda repellat animi in nisi nihil natus deleniti facere soluta aliquid libero possimus praesentium.</p>
<p>Beatae ratione nulla voluptatem. Atque, nobis, distinctio possimus deserunt esse doloribus quibusdam soluta minima qui culpa aliquam reiciendis libero molestias ipsa ipsum fugiat a odit dignissimos placeat autem. Voluptate, eaque.</p>
<p>Maiores, esse, reiciendis velit saepe quis harum debitis molestias pariatur soluta quisquam aperiam neque voluptas ducimus voluptatum ad reprehenderit unde assumenda mollitia officia blanditiis optio tenetur itaque alias ab cum.</p>
<p>Nesciunt, suscipit, eius, molestias libero neque possimus laudantium inventore maiores ab dolorem officiis laborum error maxime esse illo facere in optio omnis dolore odio tempora impedit molestiae repellat pariatur a.</p>
</article>
<aside id="page-sidebar">
<header><h1>Sidebar</h1></header>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis, labore, impedit, in nihil expedita praesentium nobis modi quidem suscipit vero quis repellat quo culpa ut eligendi iusto dicta tempora dolor.</p>
<ul>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
<li>Link4</li>
</ul>
</aside>
<footer><p>© Copyright 2014</p></footer>
</div>
</body>
</html>
body {
margin: 0;
padding: 0;
color: #000;
background: #808080;
}
header > h1 {
margin: 0 0 1em;
}
#page-wrap {
max-width: 750px;
margin: 0 auto;
background: #b2b2b2;
}
#page-wrap > header {
padding: 5px 10px;
text-align: center;
background: #cccccc;
}
#page-wrap > aside {
padding: 5px 10px;
background: #c99;
float: left;
width: 230px;
padding-left: 10px;
background: #c99;
}
#page-wrap > nav ul {
margin: 0;
padding-left: 10px;
list-style: none;
word-spacing: 20px;
}
#page-wrap > nav li {
display: inline;
margin: 0;
padding: 0;
}
#page-wrap > article {
float: left;
max-width: 480px;
padding: 10px;
background: #9c9;
}
#page-wrap > footer {
clear: both;
padding: 5px 10px;
background: #cc9;
}