.htmlsoubor
index.html,
index2.html,
index3.html, ...
./- aktuální složka
../- nadřazená složka
Většina prohlížečů automaticky odsazuje prvky.
margin
margin-top,
margin-right,
margin-bottom,
margin-left
<!DOCTYPE html>
<html>
<head>
<style>
p {
margin: 30px;
}
</style>
</head>
<body>
<p>Ahoj Honzo</p>
</body>
</html>
padding
padding-top,
padding-right,
padding-bottom,
padding-left
<!DOCTYPE html>
<html>
<head>
<style>
div{
width: 200px;
height: 200px;
background-color: antiquewhite;
padding: 30px;
}
</style>
</head>
<body>
<div>
<p>Ahoj Honzo</p>
</div>
</body>
</html>
border
border-top,
border-right,
border-bottom,
border-left
<!DOCTYPE html>
<html>
<head>
<style>
div{
width: 100px;
height: 100px;
background-color: antiquewhite;
padding: 30px;
border: 20px solid green;
}
</style>
</head>
<body>
<div>
<p>Ahoj Honzo</p>
</div>
</body>
</html>
padding,
border,
margin
border-radius- vlastnost pro zaoblení rohů
pixelech
<!DOCTYPE html>
<html>
<head>
<style>
div{
width: 100px;
height: 100px;
background-color: antiquewhite;
border-radius: 5px;
}
</style>
</head>
<body>
<div>
<p>Ahoj Honzo</p>
</div>
</body>
</html>
widtha
height
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
margin-left: auto;
margin-right: auto;
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
div p
div > p
div + p
div ~ p
div, p
:hover- při najetí myší
:active- při kliknutí
:focus- při zaměření
display- vlastnost pro změnu zobrazení elementu
block,
inline,
inline-block,
flex,
grid
block- element zabírá celou šířku stránky a začíná na novém řádku
div,
h1,
p
<!DOCTYPE html>
<html>
<head>
<style>
div {
/*display: block;*/
height: 100px;
background-color: cadetblue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
inline- element zabírá jen tolik místa, kolik potřebuje a nezačíná vždy na novém řádku
span,
a
<!DOCTYPE html>
<html>
<head>
<style>
span {
/*display: inline;*/
color: cadetblue;
}
</style>
</head>
<body>
<span>Toto je první span</span>
<span>Toto je druhý span</span>
</body>
</html>
inline-block- kombinuje výhody inline a block
<!DOCTYPE html>
<html>
<head>
<style>
.box {
display: inline-block;
width: 80px;
height: 80px;
background-color: lightcoral;
margin: 5px;
}
</style>
</head>
<body>
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
</body>
</html>
display: flex- vlastnost pro vytvoření flexboxu
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: flex;
background-color: lightgray;
padding: 10px;
}
.item {
background-color: coral;
padding: 20px;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</body>
</html>
justify-content- zarovnání prvků na hlavní ose
align-items- zarovnání prvků na vedlejší ose
flex-direction- směr, ve kterém se prvky budou řadit
flex-wrap- zalamování prvků
flex-start,
center,
flex-end,
space-between,
space-around
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: flex;
justify-content: center;
background-color: lightgray;
padding: 10px;
}
.item {
background-color: coral;
padding: 20px;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</body>
</html>
flex-start,
center,
flex-end,
stretch
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: flex;
align-items: center;
height: 200px;
background-color: lightgray;
padding: 10px;
}
.item {
background-color: coral;
padding: 20px;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</body>
</html>
row,
column,
row-reverse,
column-reverse
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: flex;
flex-direction: column;
background-color: lightgray;
padding: 10px;
}
.item {
background-color: coral;
padding: 20px;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: flex;
justify-content: space-between;
align-items: center;
height: 150px;
background-color: lightgray;
padding: 10px;
}
.item {
background-color: coral;
padding: 15px;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="item">Levý</div>
<div class="item">Střed</div>
<div class="item">Pravý</div>
</div>
</body>
</html>
display: grid- vytvoření mřížkového layoutu
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 10px;
background-color: lightgray;
padding: 10px;
}
.grid-item {
background-color: lightblue;
padding: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
</div>
</body>
</html>
grid-template-columns- definuje sloupce
grid-template-rows- definuje řádky
gap- mezery mezi prvky
grid-column,
grid-row- umístění konkrétního prvku
<!DOCTYPE html>
<html>
<head>
<style>
.grid-layout {
display: grid;
grid-template-columns: 200px 1fr 150px;
grid-template-rows: 60px 1fr 40px;
gap: 10px;
height: 300px;
}
.header {
grid-column: 1 / 4;
background-color: lightcoral;
padding: 10px;
}
.sidebar { background-color: lightblue; padding: 10px; }
.main { background-color: lightgreen; padding: 10px; }
.aside { background-color: lightyellow; padding: 10px; }
.footer {
grid-column: 1 / 4;
background-color: lightpink;
padding: 10px;
}
</style>
</head>
<body>
<div class="grid-layout">
<div class="header">Hlavička</div>
<div class="sidebar">Boční panel</div>
<div class="main">Hlavní obsah</div>
<div class="aside">Aside</div>
<div class="footer">Patička</div>
</div>
</body>
</html>
Interaktivní hra pro učení CSS Grid