<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>We-Des &#187; css</title>
	<atom:link href="http://www.we-des.net/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.we-des.net</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 09:33:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>CSS, una guida introduttiva</title>
		<link>http://www.we-des.net/css-unintroduzione/</link>
		<comments>http://www.we-des.net/css-unintroduzione/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 21:15:13 +0000</pubDate>
		<dc:creator>Gianmarco Simone</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Webdesign]]></category>
		<category><![CDATA[guida]]></category>

		<guid isPermaLink="false">http://www.we-des.net/?p=875</guid>
		<description><![CDATA[I CSS (Cascading Style Sheet) sono usati per descrivere l&#8217;aspetto di una pagina (X)HTML e sono stati creati dal W3C per separare i contenuti di una pagina web dalla presentazione (l&#8217;aspetto) e permettere una migliore e più semplice programmazione. Questa mini-guida è pensata per introdurre i neofiti all&#8217;arte del web-design e sarà l&#8217;inizio di una [...]]]></description>
			<content:encoded><![CDATA[<p>I <strong>CSS (Cascading Style Sheet)</strong> sono usati per descrivere l&#8217;aspetto di una pagina (X)HTML e sono stati creati dal <a href="http://www.w3c.org">W3C</a> per separare i contenuti di una pagina web dalla presentazione (l&#8217;aspetto) e permettere una migliore e più semplice programmazione. Questa mini-guida è pensata per introdurre i neofiti all&#8217;arte del web-design e sarà l&#8217;inizio di una lunga serie di articoli.</p>
<p><span id="more-875"></span></p>
<p>Innanzitutto, occupiamoci di come <strong>includere</strong> i CSS nelle nostre pagine web. Possiamo farlo in due modi, vediamo quali sono:</p>
<p><strong>Fogli esterni:</strong><br />
Si crea un file con estensione .css esterno alla pagina html e si richiama con il codice</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;foglio_di_stile.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p><em>Nota:</em><br />
Per fogli di stile multipli basta aggiungere un&#8217;altra stringa cambiando il nome del foglio di stile.</p>
<p><strong>Fogli interni:<br />
</strong><br />
Per stili di poche righe, è possibile includere il codice css direttamente nel tag head</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
*codice css*
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><em>Nota</em>:<br />
Assolutamente da evitare il css inline, ovvero lo scrivere lo stile di ogni elemento, direttamente all&#8217;interno del suo tag, come attributo della proprietà style:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;width: 100px; height: 100px; border: 2px solid red;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
*contenuto*
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>I CSS sono formati da set di <em>regole</em> applicate a <em>selettori</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tag</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mioId&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;miaClasse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">tag<span style="color: #00AA00;">&#123;</span>
proprietà<span style="color: #00AA00;">:</span> valore<span style="color: #00AA00;">;</span>
proprietà<span style="color: #00AA00;">:</span> valore<span style="color: #00AA00;">,</span> valore<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#id</span><span style="color: #00AA00;">&#123;</span>
 proprietà<span style="color: #00AA00;">:</span> valore<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
.classe<span style="color: #00AA00;">&#123;</span>
 proprietà<span style="color: #00AA00;">:</span> valore<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>Tipi di Selettori:</strong></p>
<p><em><strong>	Selettori di tipo<br />
</strong></em></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body<span style="color: #00AA00;">&#123;</span>
...
<span style="color: #00AA00;">&#125;</span>
&nbsp;
p<span style="color: #00AA00;">&#123;</span>
...
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Applicano le regole a tutti gli elementi di un certo tipo (associati ai tag html)</li>
<p><em>	<strong>Classi</strong><br />
</em></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;miaClasse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
Questo testo sarà sottoposto alle regole di chiarate per la classe miaClasse
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.miaClasse<span style="color: #00AA00;">&#123;</span>
...
<span style="color: #00AA00;">&#125;</span>
&nbsp;
.miaClasse2<span style="color: #00AA00;">&#123;</span>
...
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>	<em><strong>Identificatori</strong></em></p>
<p>Vengono applicano univocamente all&#8217;elemento con l&#8217;identificatore (ID) definito:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mioId&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>* contenuto*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mioId2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>* contenuto*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#mioId</span><span style="color: #00AA00;">&#123;</span>
...
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#mioId2</span><span style="color: #00AA00;">&#123;</span>
...
<span style="color: #00AA00;">&#125;</span></pre></div></div>

</li>
<p><em><strong>Pseudoselettori:</strong></em></p>
<p>Si tratta di selettori particolari che applicano le regole ad un elemento solo in determinate condizioni, ad esempio:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
...
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Applica le regole di stile all&#8217;elemento quando il puntatore ci si trova sopra.</p>
<p><em><strong>Selettori di discendenza:</strong><br />
</em><br />
Sono selettori che applicano le regole solo ad un elemento parente che si trovi all&#8217;interno di un elemento contenitore</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 Le regole NON saranno applicate a questo paragagrafo.
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;contenitore&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> Le regole saranno applicate a questo paragrafo.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#contenitore</span><span style="color: #00AA00;">&#123;</span>
...
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>L&#8217;effetto sarebbe identico anche se p non fosse direttamente all&#8217;interno di contenitore</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                 Le regole saranno applicate a questo paragrafo.
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong><em>Priorità dei selettori:</em><br />
</strong><br />
Se allo stesso elemento vengono associati più selettori, l&#8217;id avrà priorità assoluta, seguito dalla classe e dal selettore di elemento.<br />
Ad esempio:</p>
<p class="miaClasse">

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
.miaClasse<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#mioId</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">white</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Si possono associare più classi ad un solo elemento e in caso di sovrapposizione delle regole, saranno applicate quelle più in fondo nel file di testo (che quindi saranno lette dopo dal browser).<br />
Esempio:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;miaClasse1,miaClasse2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Contenuto<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.miaClasse1<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
.miaClasse2<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Saranno applicate le regole di miaClasse2 perchè si trovano più in fondo rispetto a miaClasse1.</p>
<p><strong><em>Commenti</em></strong></p>
<p>Chiudo con un piccolo esempio sulla sintassi per i commenti in css, cioè porzioni di testo che non vengono interpretate dal browser.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">/* Commenterà 
tutto il testo 
compreso.   
*/</span></pre></div></div>

<p>Questo è solo l&#8217;inizio, c&#8217;è ancora molto da dire ma queste sono le basi che vi serviranno per seguire quello che verrà successivamente. Per domande, critiche, suggerimenti, minacce di morte, regali, dichiarazioni d&#8217;amore e tutto, usate i commenti.<br />
<h3>Articoli simili</h3>
<ul class="related_post">
<li><a href="http://www.we-des.net/drawter/" title="Drawter layout con due click">Drawter layout con due click</a></li>
<li><a href="http://www.we-des.net/artist-from-the-web-shinybinary/" title="Artist from the WEB: ShinyBinary">Artist from the WEB: ShinyBinary</a></li>
<li><a href="http://www.we-des.net/5-siti-e-un-contest-da-non-perdere/" title="5 Siti (e un contest) &#8220;da non perdere&#8221; ">5 Siti (e un contest) &#8220;da non perdere&#8221; </a></li>
<li><a href="http://www.we-des.net/sito-del-giorno-quitdoingit/" title="Sito del Giorno: QuitDoingIt">Sito del Giorno: QuitDoingIt</a></li>
<li><a href="http://www.we-des.net/sito-del-giorno-sensisoft/" title="Sito del Giorno : SensiSoft">Sito del Giorno : SensiSoft</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.we-des.net/css-unintroduzione/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.739 seconds -->

