1.Díl: Úvodem
Úvodem
Co by jste měli umět, než se pustíte do CSS?
- Základy HTML (bez toho se CSS ani nepokoušejte naučit), zde vám pomůže seriál o základech HTML, který v této knihovně naleznete.
- Základy práce se soubory
Jaké vybavení potřebujete pro kurz?
- Jednoduchý textový editor, stačí poznámkový blok nebo PSPad.
- Správce souborů, postačí průzkumník Windows nebo Total Commander.
- Hodně trpělivosti :o)
K čemu to tedy je?
Odpověď je snadná. CSS slouží k vylepšenému formátování stránek a každý, kdo chce vytvářet kvalitní webové stránky by měl zvládnou alespoň jeho základy.
Teď ale od teorie k praxi. Zkusíme metodu hození do ledové vody a plavání. Zkuste použít na stránce HTML tento kratičký kód:
<span style="color: red">Tenhle text formátuje CSS!</span>
Co se nestalo? Text v tagu span je červený. Nadefinovali jsme to přes parametr style="" . Aha, teď si asi tak říkáte, k čemu to je, když bych to mohl udělat po „HTMlovsku" jen pomocí tagu font:
<font color="red">Tento text formátuje pouze HTML</font>
Efekt je stejný. Co kdybychom ale chtěli udělat text ještě kurzívou. V HTML by to vypadalo asi nějak takhle:
<font color="red"><i>Tento text formátuje pouze jenom HTML</i></font>
K formátování jsme použili dva tagy. Sami uznáte, že v tom někdy bývá docela nepořádek. Pomocí CSS to samé formátování můžete provést mnohem elegantněji:
<span style="color: red; font-style: italic">Tento text formátuje opět CSS</span>
V CSS se dají nastavovat ale i vlastnosti elementů, které pomocí HTML normálně ani nastavit nejdou. Třeba barvu pozadí nějakého textu:
<span style="background-color: blue">Mám modré pozadí díky CSS</span>
Tak to je jenom drobná ukázka toho co CSS dovede.
Kaskádovitost
Hlavní kouzlo CSS je ale v jeho kaskádovitosti. Pokud formátuji HTML dokument pomocí CSS, nepřiděluji většinou každému tagu CSS styl pomocí parametru Style="" ale definuji vlastnosti tagů globálně pro celý dokument.
Například: Určím, že tag <h1> (první nadpis) bude zarovnaný na střed, modrou barvou, písmo Arial velikost 16 a text bude potržený. Potom pokaždé, když použiji tag <h1>, zformátuje se jeho obsah automaticky podle předem určených hodnot.
Zní to moc hezky, ale jak to udělat prakticky? Takhle:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Příklad HTML a CSS</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<style>
h1 {text-align: center; font-family: Arial; font-size: 16; color: blue; text-decoration: underline}
</style>
</head>
<body>
<h1>Tadá! CSS se projevilo</h1>
Ten nadpis vypadá ale pěkně.
</body>
</html>
A výsledek:
Vlastní definice CSS jsou zde uvedeny v hlavičce, v obsahu tagu <style>. Je tam jenom jeden řádek:
h1 {text-align: center; font-family: Arial; font-size: 16; color: blue; text-decoration: underline}
Jako první se do definice stylu uvádí název tagu. V tomto případě h1. Za tím následují složené závorky. Ve složených závorkách se uvádějí samotné formátovací vlastnosti a to v tomto formátu:
"{vlastnost1: hodnota1; vlastnost2: hodnota2;}".
Schválně jsem tam zvýraznil dvojtečky a středníky, protože bez jejich správného zápisu vám prohlížeč nebude CSS interpretovat správně!
Takto můžete nadefinovat vzhled skoro každého tagu a přidělit mu formát, jaký si jen přejete.
Externí stylopis
Jsou tři možnosti zápisu CSS. Dvě z nich jsme si už předvedli. První je pomocí parametru style u tagu, na který chcete styl aplikovat. Druhá je umístěním tagu style do hlavičky a vypsání všech CSS stylů do tagu <style>. A třetí způsob, ten který jsme si ještě neukazovali, se provádí pomocí tagu link.
Zápis je stejný jako u druhého způsobu, ale obsah tagu style se umísťuje do externího souboru s příponou .css . Na tento externí stylopis se pak dokumentu HTML odkazuje pomocí tagu link: <link rel="stylesheet" type="text/css" href="stylopis.css">. Do parametru href se zapisuje cesta k stylopisu.
Tag link se umísťuje do hlavičky HTML dokumentu. Toto řešení stylů se v praxi používá nejčastěji, protože jednu definici stylů můžeme použít u více stránek, jelikož je umístěna externě. Snadno tak můžeme formátovat třeba styly všech stránek na jednom webu pomocí jednoho externího stylopisu.
Teď zkusíme převést naposledy předváděný příklad, aby vyhovoval provedení třetího způsobu zápisu CSS:
Obsah souboru priklad2.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Příklad HTML a CSS 2</title>
<link rel="stylesheet" type="text/css" href="styly.css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
</head>
<body>
<h1>Tadá! CSS se projevilo</h1>
Ten nadpis vypadá ale pěkně.
</body>
</html>
Obsah souboru styly.css:
h1 {text-align: center; font-family: Arial; font-size: 16; color: blue; text-decoration: underline}
Efekt je úplně stejný jako u předcházejícího příkladu. Tento příklad bude samozřejmě fungovat jen, když máte vytvořený soubor styly.css umístěn ve stejném adresáři jako stránku HTML samotnou.
Identifikátory a třídy
Zřejmě nebudete chtít definovat styl jenom tagů samotných, to by vám styly asi brzy došly. Pro další možnosti přiřazování stylů jsou zde třídy a indetifikátory. Těchto záhadných názvů se není třeba vůbec bát, je to úplně jednoduché.
Identifikátory a třídy mají aplikačně stejný efekt. Jediný rozdíl je v zápisu. Správně by se ID (zkratka identifikátoru) mělo používat pouze jedenkrát v celém HTML dokumentu, ale nikomu nebude vadit, i když to omylem použijete vícekrát.
ID se zapisuje s mřížkou (#) před názvem identifikátoru. Třída s obyčejnou tečkou před názvem. A jak se třídy a identifikátory používají v praxi?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Ukázka tříd & identifikatorů</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<style>
span {font-family: Arial, Helvetica, sans-serif; color: lime;}
#uvod {color: blue; background-color: black;}
.zaver {font-size: 36px; font-style: italic; text-decoration: underline;}
</style>
</head>
<body>
<span id="uvod">Víejte na této úžasné stránce formátované pomocí CSS</span><br>
<span>Je fakt supr-čupr! :-)</span>
<span class="zaver">Co říkáte?</span>
</body>
</html>
Pro větší přehlednost používám v příkadech interní stylopis v hlavičce, ale dá se to samozřejmě všechno udělat i externě.
V tomto příkladu je použit jeden identifikátor, jedna třída a jedna definice stylu tagu span. Vidíte, že tagům se definice tříd a indetifikátorů přiřazují pomocí parametrů class a id. Do parametru se názvy tříd a IDček samozřejmě zapisují bez uvozovacího znaku
(# a .).
Zároveň je tu ukázka efektu kaskádovitosti. U tagu span je definována barva color: lime, ale u ID uvod je použitá barva color: blue Jakou barvu bude mít tedy text v tagu span s ID úvod?
Modrou! A proč?
Toto je právě efekt kaskádovitosti. Definice tagu span je ve formátovací hierarchii vzdálenější než definice ID úvod. Proto se na text aplikuje barva modrá. Samozřejmě všechny formátovací vlastnosti, které v ID uvod neurčíte, převezme obsah tagu span přímo zjeho definice.
Na závěr prvního dílu ještě krátká ukázka jednoduché stránky formátované přes CSS. Berte to jako opakování:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Opakování probrané látky o CSS</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<style>
body {background-color: black;}
h1 {text-align: center; color: #CCCCCC;}
#zacatek {font-style: italic; color: #00FF66;}
p {color: #FFFFFF;}
.zvyrazneni {font-weight: bolder; background-color: #666666;}
#zaver {color: #0099FF; text-decoration: underline;}
</style>
</head>
<body>
<h1>Příkady úžasného CSS</h1>
<p id="zacatek" class="zvyrazneni">CSS je super věc pro formátování webových HTML stránek a měli by ho ovládat všichni zkušení webdesingeři.</p>
<p>Není moc složité a dají se s ním dělat opravdu velké věci!</p>
<p class="zvyrazneni">Jeden stylopis můžete použít u více HTML stránek, když bude umístěn externě.</p>
<p id="zaver">Tak co říkáte, líbí se vám CSS?</p>
</body>
</html>
Komentáře
Přehled komentářů
Simply desire to say your article is as astonishing. The clearness in your post is simply cool and i could assume you're an expert on this subject. Fine with your permission let me to grab your feed to keep up to date with forthcoming post. Thanks a million and please carry on the enjoyable work. orke.aresgrb.se/relaxation/mal-au-doigt-de-pied-chaussure.php mal au doigt de pied chaussure
lchf till vardags tastyandinteresting.be
(tastyandinteresting.be, 26. 6. 2020 15:41)
You have made some good points there. I checked on the internet to learn more about the issue and found most people will go along with your views on this web site. tastyandinteresting.be/decorations/yr-mr-illa.php lchf till vardags
roda utslag pa benen vuxen goodprizwomen.com
(goodprizwomen.com, 25. 6. 2020 22:36)
Do you mind if I quote a few of your articles as long as I provide credit and sources back to your blog? My blog is in the exact same niche as yours and my visitors would really benefit from some of the information you provide here. Please let me know if this okay with you. Many thanks! tchiw.goodprizwomen.com/travels/roeda-utslag-p-benen-vuxen.php roda utslag pa benen vuxen
varfГ¶r fГҐr man soleksem tastyandinteresting.be
(tastyandinteresting.be, 25. 6. 2020 3:03)
Very quickly this web page will be famous among all blogging people, due to it's good articles or reviews tastyandinteresting.be/beauty/jaren-50-kleding.php varfГ¶r fГҐr man soleksem
farga gratt har med kaffe aresgrb.se
(aresgrb.se, 24. 6. 2020 16:56)
First of all I would like to say terrific blog! I had a quick question in which I'd like to ask if you do not mind. I was interested to know how you center yourself and clear your mind prior to writing. I've had difficulty clearing my mind in getting my ideas out there. I truly do take pleasure in writing but it just seems like the first 10 to 15 minutes are usually wasted just trying to figure out how to begin. Any recommendations or tips? Many thanks! beire.aresgrb.se/travels/faerga-grtt-hr-med-kaffe.php farga gratt har med kaffe
vitamin well 002 tastyandinteresting.be
(tastyandinteresting.be, 23. 6. 2020 4:09)
Since the admin of this web site is working, no question very shortly it will be famous, due to its feature contents. tastyandinteresting.be/for-men/hus-till-salu-i-ystad.php vitamin well 002
smal avfГ¶ring fГ¶rstoppning tastyandinteresting.be
(tastyandinteresting.be, 18. 6. 2020 23:33)
Its such as you read my thoughts! You appear to understand a lot approximately this, like you wrote the e book in it or something. I believe that you simply could do with some p.c. to pressure the message house a little bit, but instead of that, this is wonderful blog. An excellent read. I will definitely be back. tastyandinteresting.be/beauty/goera-egna-gelenaglar-depend.php smal avfГ¶ring fГ¶rstoppning
begagnade bilar online aresgrb.se
(aresgrb.se, 16. 6. 2020 21:01)
I don't even know how I stopped up here, however I assumed this post used to be good. I don't recognize who you might be but certainly you are going to a famous blogger in case you are not already. Cheers! texna.aresgrb.se/relaxation/begagnade-bilar-online.php begagnade bilar online
creme corps chocolat tastyandinteresting.be
(tastyandinteresting.be, 14. 6. 2020 22:51)
Amazing! Its truly amazing post, I have got much clear idea about from this paragraph. tastyandinteresting.be/useful-tips/akut-trombotiserad-hemorrojd.php creme corps chocolat
Hi! Only from 18+!
(Sandragof, 10. 6. 2020 17:39)Hurry up to look into loveawake.ru you will find a lot of interesting things....
lammrygg med ben recept aresgrb.se
(aresgrb.se, 10. 6. 2020 9:29)
Howdy! Do you use Twitter? I'd like to follow you if that would be ok. I'm absolutely enjoying your blog and look forward to new posts. unem.aresgrb.se/music/lammrygg-med-ben-recept.php lammrygg med ben recept
sveriges mästerkock 2015 tastyandinteresting.be
(tastyandinteresting.be, 9. 6. 2020 0:19)
I do trust all of the ideas you've introduced in your post. They are very convincing and can certainly work. Still, the posts are very short for newbies. May you please extend them a little from next time? Thanks for the post. tastyandinteresting.be/beauty/recept-p-flaeskfilegryta.php sveriges mästerkock 2015
knackebrod recept utan jast aresgrb.se
(aresgrb.se, 8. 6. 2020 17:24)
I have to thank you for the efforts you have put in writing this website. I really hope to view the same high-grade blog posts from you in the future as well. In fact, your creative writing abilities has motivated me to get my very own website now ;) viobel.aresgrb.se/sport/knaeckebroed-recept-utan-jaest.php knackebrod recept utan jast
opstart af firma aresgrb.se
(aresgrb.se, 6. 6. 2020 10:45)
Simply desire to say your article is as surprising. The clearness in your post is simply spectacular and i could assume you're an expert on this subject. Well with your permission let me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please carry on the rewarding work. ispa.aresgrb.se/decorations/opstart-af-firma.php opstart af firma
fisse uden hГҐr tastyandinteresting.be
(tastyandinteresting.be, 5. 6. 2020 22:42)
Nice response in return of this issue with genuine arguments and telling the whole thing concerning that. tastyandinteresting.be/decorations/svider-i-aeggstockarna.php fisse uden hГҐr
lattlagad bjudmat till manga aresgrb.se
(aresgrb.se, 4. 6. 2020 6:38)
Hey there! This is kind of off topic but I need some guidance from an established blog. Is it tough to set up your own blog? I'm not very techincal but I can figure things out pretty fast. I'm thinking about creating my own but I'm not sure where to start. Do you have any points or suggestions? Cheers ylbam.aresgrb.se/delicious-dishes/laettlagad-bjudmat-till-mnga.php lattlagad bjudmat till manga
ser dГҐligt med linser tastyandinteresting.be
(tastyandinteresting.be, 2. 6. 2020 6:31)
Highly energetic post, I enjoyed that a lot. Will there be a part 2? tastyandinteresting.be/decorations/tor-network-wikipedia.php ser dГҐligt med linser
nattlinne och morgonrock aresgrb.se
(aresgrb.se, 2. 6. 2020 2:04)
If you would like to take a good deal from this post then you have to apply such techniques to your won weblog. racir.aresgrb.se/relaxation/nattlinne-och-morgonrock.php nattlinne och morgonrock
hotell tre liljor aresgrb.se
(aresgrb.se, 30. 5. 2020 12:28)
Howdy! Quick question that's entirely off topic. Do you know how to make your site mobile friendly? My site looks weird when browsing from my iphone. I'm trying to find a theme or plugin that might be able to resolve this issue. If you have any recommendations, please share. Many thanks! lomi.aresgrb.se/for-women/hotell-tre-liljor.php hotell tre liljor
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75
mal au doigt de pied chaussure aresgrb.se
(aresgrb.se, 28. 6. 2020 17:20)