Come formattare pagine web utilizzando My Style Sheet

June 23

Come formattare pagine web utilizzando My Style Sheet


fogli di stile CSS forniscono un meccanismo per l'aggiunta di stili di pagine web e separare la semantica pagina di presentazione dal contenuto della pagina. CSS è stato originariamente sviluppato per risolvere i problemi introdotti con l'inclusione di informazioni di stile nel tag HTML, una pratica che ha portato al codice HTML ingestibile e costoso. I fogli di stile offrono agli sviluppatori la possibilità per lo stile l'aspetto delle pagine web in modo coerente ed estensibile riservando tag HTML per la descrizione del contenuto stesso.

istruzione

Come formattare pagine web utilizzando un foglio di stile esterno

1 Aprire un editor di testo e creare un nuovo file. Nome del file myStylesheet.css.

2 Modifica myStylesheet.css. Aggiungere uno stile al file che i colori "<p>" tag utilizzati in qualsiasi pagina web che fa riferimento a myStylesheet.css rosso. Salvare e chiudere myStylesheet.css.

p

{

colore rosso;

}

3 Rientro in editor di testo, e creare un nuovo file. Nome del file useExternal.html e salvarlo nella stessa posizione myStylesheet.css.

4 Modifica useExternal.html. Aggiungete un po 'HTML al file che include un HTML aperto "<html>" tag, un HTML aperto "<head>" tag, una stretta HTML "</ head>" tag, un HTML aperto "<body>" tag, un vicino HTML "<body />" tag e una stretta HTML "</ html>" tag.

<Html>

<Head> </ head>

<Body> </ body>

</ Html>

5 Continuare a modificare useExternal.html. Aggiungere un collegamento a myStylesheet.css nella sezione del file "<head>". Impostare il valore "href" a "myStylesheet.css", il valore "rel" a "text / foglio di stile" e il valore "tipo" a "text / css".

<Html>

<Head>

<Link href = "myStylesheet.css" rel = "stylesheet" type = "text / css">

</ Head>

<Body> </ body>

</ Html>

6 Continuare a modificare useExternal.html. Aggiungere un "<h1>" tag di intestazione HTML al file nella sezione "<body>", impostare l'intestazione per il testo "Intestazione testo" e chiudere il "</ h1>" tag.

<Html>

<Head>

<Link href = "myStylesheet.css" rel = "stylesheet" type = "text / css">

</ Head>

<Body>

<H1> Testo intestazione </ h1>

</ Body>

</ Html>

7 Continuare a modificare useExternal.html. Aggiungere un HTML "<p>" tag di paragrafo al file seguendo la "<h1>" tag, impostare il testo paragrafo per "Paragrafo testo" e chiudere il tag "</ p>". Salvare e chiudere useExternal.html.

<Html>

<Head>

<Link href = "myStylesheet.css" rel = "stylesheet" type = "text / css">

</ Head>

<Body>

<H1> Testo intestazione </ h1>

<P> Paragrafo testo </ p>

</ Body>

</ Html>

8 Aprire useExternal.html in un browser web. Verificare che il testo inserito all'interno del "<p>" e "</ p>" tag è colorato in rosso.

Come formattare una pagina Web utilizzando un foglio di stile interno

9 Aprire un editor di testo e creare un nuovo file chiamato useInternal.html. Aggiungete un po 'HTML al file che include un HTML aperto "<html>" tag, un HTML aperto "<head>" tag, una stretta HTML "</ head>" tag, un HTML aperto "<body>" tag, un vicino HTML "<body />" tag, e una stretta HTML "</ html>" tag.

<Html>

<Head> </ head>

<Body> </ body>

</ Html>

10 Continuare a modificare useInternal.html. Aggiungere uno stile tra il "<head>" e "</ head>" tag che i colori qualsiasi testo che utilizza il tag "<p>" blu.

<Html>

<Head>

<Style type = "text / css">

p

{

colore blu;

}

</ Style>

</ Head>

<Body> </ body>

</ Html>

11 Continuare a modificare useInternal.html. Aggiungere un "<h1>" tag di intestazione HTML alla sezione "<body>" del file e impostare il testo di intestazione di "Testo intestazione". Chiudere il "</ h1>" tag.

<Html>

<Head>

<Style type = "text / css">

p

{

colore blu;

}

</ Style>

</ Head>

<Body>

<H1> Testo intestazione </ h1>

</ Body>

</ Html>

12 Continuare a modificare useInternal.html. Aggiungere un HTML "<p>" tag di paragrafo al file seguendo la "<h1>" tag e impostare il testo paragrafo per "Paragrafo testo". Chiudere il tag "</ p>" e salvare e chiudere useInternal.html.

<Html>

<Head>

<Style type = "text / css">

p

{

colore blu;

}

</ Style>

</ Head>

<Body>

<H1> Testo intestazione </ h1>

<P> Paragrafo testo </ p>

</ Body>

</ Html>

13 Aprire useInternal.html in un browser web. Verificare che il testo inserito all'interno del "<p>" e "</ p>" tag è di colore blu.

Come formattare una pagina Web utilizzando un foglio di stile in linea

14 Aprire un editor di testo e creare un nuovo file chiamato useInline.html. Aggiungete un po 'HTML al file che include un HTML aperto "<html>" tag, un HTML aperto "<head>" tag, una stretta HTML "</ head>" tag, un HTML aperto "<body>" tag, un vicino HTML "<body />" tag, e una stretta HTML "</ html>" tag.

<Html>

<Head> </ head>

<Body> </ body>

</ Html>

15 Continuare a modificare useInline.html. Aggiungere un "<h1>" tag di intestazione HTML nella sezione "<body>" del file, impostare l'intestazione per il testo "Intestazione testo" e chiudere il "</ h1>" tag.

<Html>

<Head> </ head>

<Body>

<H1> Testo intestazione </ h1>

</ Body>

</ Html>

16 Continuare a modificare useInline.html. Aggiungere un HTML "<p>" tag di paragrafo al file seguendo la "<h1>" tag, impostare il testo paragrafo per "Paragrafo testo" e chiudere il tag "<p>".

<Html>

<Head> </ head>

<Body>

<H1> Testo intestazione </ h1>

<P> Paragrafo testo </ p>

</ Body>

</ Html>

17 Continuare a modificare useInline.html. Modificare il "<p>" tag di paragrafo e aggiungere un parametro "stile" che i colori qualsiasi testo che utilizza il "<p>" tag verde.

<Html>

<Head> </ head>

<Body>

<H1> Testo intestazione </ h1>

<P style = "color: green;"> Paragrafo testo </ p>

</ Body>

</ Html>

18 Aprire useInline.html in un browser web. Verificare che il testo inserito all'interno del "<p>" e "</ p>" tag è colorato di verde.

Consigli e avvertenze

  • CSS può essere usato per lo stile font, sfondi, testo, e offre box e classificazione proprietà.
  • CSS3 sfrutta moduli che forniscono caratteristiche di stile più avanzate, come i bottoni arrotondati ed effetti di testo.
  • CSS2 permette di mira delle regole ai tipi di supporti specifici utilizzando l'attributo "media".
  • Alcuni browser, in particolare di Internet Explorer, supportano le estensioni proprietarie CSS. Queste estensioni possono causare problemi quando vengono visualizzati in altri browser.
  • stili in linea non sono considerati una delle migliori pratiche, dal momento che non si separano i tag HTML (contenuto) da stile.
  • Wrapping stili nei commenti HTML ( "<-") e ( "->") nasconde codice di stile ai vecchi browser che mancano stile supporto.