CSS (англ. Cascading Style Sheets — каскадные таблицы стилей) — формальный язык описания внешнего вида документа, написанного с использованием языка разметки.
Преимущественно используется как средство описания, оформления внешнего вида веб-страниц, написанных с помощью языков разметки HTML и XHTML, но может также применяться к любым XML-документам, например, к SVG или XUL CSS используется создателями веб-страниц для задания цветов, шрифтов, расположения отдельных блоков и других аспектов представления внешнего вида этих веб-страниц. Основной целью разработки CSS являлось разделение описания логической структуры веб-страницы (которое производится с помощью HTML или других языков разметки) от описания внешнего вида этой веб-страницы (которое теперь производится с помощью формального языка CSS). Такое разделение может увеличить доступность документа, предоставить большую гибкость и возможность управления его представлением, а также уменьшить сложность и повторяемость в структурном содержимом. Кроме того, CSS позволяет представлять один и тот же документ в различных стилях или методах вывода, таких как экранное представление, печатное представление, чтение голосом (специальным голосовым браузером или программой чтения с экрана), или при выводе устройствами, использующими шрифт Брайля. По сути, формат CSS — это обычный текстовый файл. В файле .css не содержится ничего, кроме перечня правил CSS и комментариев к ним. когда таблица стилей находится в отдельном файле, она может быть подключена к веб-документу посредством тега <link>, располагающегося в этом документе между тегами <head> и </head>. (Тег <link> будет иметь атрибут href, имеющий значением адрес этой таблицы стилей). Все правила этой таблицы действуют на протяжении всего документа;
<!DOCTYPE html>
<html>
<head>
.....
<link rel="stylesheet" href="Style.css">
</head>
<body>
.....
</body>
</html>
Для проверки и настройки стилей можно использовать этот онлайн редактор, этот, этот, этот или этот
Для быстрого написания и проверки кода используйте этот генератор
Ещё полезности:
Рисовалка анимированных теней
Ultimate CSS Gradient Generator
Longshadows
css3clickchart.com
yoksel.github.io
gradientfinder.com
Растягиваем фон на всю страницу с помощью CSS
body {background: url('bg.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;}
Текст ссылки одного цвета, а подчеркивание другого цвета
<html>
<head>
<style type="text/css">
A {color:red;}
A SPAN {color: blue;}
</style>
</head>
<body>
<a href="#"><span>Пример ссылки </span></a>
</body>
</html>
Ссылки, отталкивающие скобки
<html>
<head>
<style type="text/css">
A.pushLink { padding: 0 3px; font-weight: bold; text-decoration: none; }
A:hover.pushLink { padding: 0; }
A:hover.pushLink span { margin: 0 3px; color: red; }
</style>
</head>
<body>
<a class="pushLink" href="">[ <span>CSS cсылки</span> ]</a>
</body>
</html>
Задать цвет hr через CSS
/Цвет hr элемента
hr {
color:red;
background-color:red;
height: 1px;
border-width:0px; /* убрать рамки вокруг элемента */
}
Верхний индекс нижний индекс текста
vertical-align: sub; /* превращает текст в нижний индекс; */ vertical-align: super; /* превращает текст в верхний индекс; */
Курсор определенный пользователем
P { cursor : url("my.cur"), text; }
P { cursor : url("my.svg"), url("my.cur"), auto; }
Создание буквицы с помощью CSS
<style type="text/css">
P:first-letter {color:red; font-size:200%; float:left}
</style>
Подчеркнутый пунктиром текст
<style type="text/css">
.dashedtext
{
border-bottom: 1px dashed red;
}
</style>
<span class="dashedtext">Строка подчеркнутая пунктиром.</span>
Всплывающая подсказка
<style type="text/css">
h3 {
margin-top: 50px;
}
.tooltip {
position: relative;
background: #eaeaea;
cursor: help;
display: inline-block;
text-decoration: none;
color: #222;
outline: none;
text-indent: 0;
padding: 0 3px;
}
.tooltip:hover:before {
content: attr(data-title);
white-space: pre-line;
position: absolute;
bottom: 30px;
left: 50%;
z-index: 9999;
width: 230px;
margin-left: -127px;
padding: 10px;
border: 2px solid #ccc;
opacity: .9;
background-color: #ddd;
background-image: -webkit-linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
background-image: -moz-linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
background-image: -ms-linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
background-image: -o-linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
background-image: linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
-moz-border-radius: 4px;
border-radius: 4px;
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.5) inset;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.5) inset;
box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.5) inset;
text-shadow: 0 1px 0 rgba(255,255,255,.4);
}
.tooltip:hover:after {
content: "";
position: absolute;
z-index: 10000;
bottom: 24px;
left: 50%;
margin-left: -8px;
border-top: 8px solid #ddd;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 0;
}
/* Yellow */
.yellow-tooltip:hover:before {
border-color: #e1ca82;
background-color: #ffeaa6;
}
.yellow-tooltip:hover:after {
border-top-color: #ffeaa6;
}
</style>
<h1>Всплывающая подсказка</h1>
<p>Чтобы посмотреть как работает эта CSS3 всплывающая подсказка, наведите курсор
<a href="#" class="tooltip yellow-tooltip"
data-title="Это первая CSS подсказка.">сюда</a>,<br> а чтобы полчить другую подсказку,
<a href="#" class="tooltip yellow-tooltip"
data-title="Это ВтораЯ подсказка, созданная исключительно с помощью CSS3.">наведите курсор сюда</a>.
</p>
Пример CSS отражения
<style type="text/css">
.main {
width: 900px;
margin: 0 auto;
padding-top: 30px;
}
/* отражаем текст */
.h1-css {
color: #000066;
font-size: 24px;
margin-bottom: 30px;
position: relative;
line-height: 24px;
}
.h1-css:after,
.menu-css a:after {
content: attr(title);
position:absolute;
left:0;
top:100%;
width:100%;
height:100%;
-moz-transform: scaleY(-1);
-o-transform: scaleY(-1);
-webkit-transform: scaleY(-1);
-ms-transform: scaleY(-1);
transform: scaleY(-1);
z-index: 1;
}
.h1-css:before,
.menu-css:before {
content: "";
display: block;
width: 100%;
height: 80%;
background:-moz-linear-gradient(top, rgba(255,255,255,0.7), rgba(255,255,255,1));
background: -o-linear-gradient(top, rgba(255,255,255,0.7), rgba(255,255,255,1));
background: -webkit-gradient(linear, left top, left bottom, from(rgba(255,255,255,0.7)), to(rgba(255,255,255,1)));
position: absolute;
left: 0;
top: 110%;
z-index: 2;
}
ul {
list-style: none;
margin-bottom: 30px;
}
li {
display: inline;
margin-right: 30px;
color: #000099;
}
li a {
text-decoration: none;
font-size: 14px;
color: #000099;
display: inline-block;
position: relative;
}
li a:hover {
color: #FF0000;
}
.menu-css {
position: relative;
}
</style>
<!--[if lte IE 9]>
<style>
.h1-after,
.menu-after {
position:absolute;
left:0;
top:100%;
z-index: 1;
background: #fff;
-ms-filter: "flipV progid:DXImageTransform.Microsoft.Alpha(opacity=50, style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy=70)";
filter: flipV progid:DXImageTransform.Microsoft.Alpha(opacity=50, style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy=70);
}
.h1-css:after,
.menu-css a:after {
display: none;
}
</style>
<script>
textReflect = function()
{
// отражение для заголовка
var el = document.getElementsByTagName("h1")[0];
el.insertAdjacentHTML("afterBegin", "<span class='h1-after'>"+el.firstChild.nodeValue+"</span>");
// отражения для меню
var menu = document.getElementsByTagName("a"),
i,
lenMenu = menu.length;
for(i=0;i<lenMenu;i++) menu[i].insertAdjacentHTML("afterBegin", "<span class='menu-after'>"+menu[i].firstChild.nodeValue+"</span>");
}
window.onload=textReflect;
</script>
<![endif]-->
<div class="main">
<div class="h1-css" title="Пример CSS отражения">Пример CSS отражения</div>
<ul class="menu-css">
<li><a href="#" title="Главная">Главная</a></li>
<li><a href="#" title="О компании">О компании</a></li>
<li><a href="#" title="Каталог">Каталог</a></li>
<li><a href="#" title="Наши контакты">Наши контакты</a></li>
</ul>
</div>
Оформление внешних ссылок пиктограмкой
<style type="text/css"><!--
.externalBlock {
display: inline;
height: 10px;
margin-left: 5px;
position: absolute;
text-decoration: none;
}
//--></style>
<h1>Оформление внешних ссылок пиктограмкой</h1>
<p>
<a href="#" title="Откроется в новом окне">Внешняя ссылка
<img class="externalBlock" src="/pic/icon/externallinks.png"></a>
</p>
Свой шрифт на странице
@font-face{ font-family: xxx; src: url(/1.ttf)}
html{font-family: xxx, Arial, sans-serif;}
Пример подключения google шрифтов на CSS
// в head
<!-- Some special fonts -->
/* Single font load*/
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Serif">
/* Multiple font load*/
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Nobile|Droid+Serif|Old+Standard+TT|Droid+Sans"><!-- Some special fonts -->
// в css
body {
font-family: 'Droid Serif', serif; font-size: 48px;
}
Текст с тенью
<style>
<!--
.container {
background-color: #fff;
display: block;
padding: 0px;
height: 200px;
width: 366px;
margin:0 auto;
border:3px solid;
border-color:#ddc #bba #bba #ddc;
overflow:hidden;
position:relative;
}
h6{font-size:50px; padding:0; margin:0;}
h6.hTop{position:absolute; top:75px; left:125px; z-index:100;}
h6.unter1{position:absolute; top:76px; left:126px; z-index:90;}
h6.unter2{position:absolute; top:77px; left:127px; z-index:80;}
/**/
.container p.p1,.container p.p2,.container p.p3{
position:absolute;
font-size:50px;
text-transform:uppercase;
font-weight:bold;
text-align:center;
}
.container p.p1{top:30px; left:110px; z-index:100;}
.container p.p2{top:33px; left:113px; z-index:90;}
.container p.p3{top:34px; left:114px; z-index:80;}
.red{color:#f00;}
.black{color:#000;}
.yellow{color:#ff0;}
.blue{color:#0ff;}
.gray{color:gray;}
pre{font-size:120%; color:#009;}
-->
</style>
<h1>Текст с тенью с помощью CSS</h1>
<h3>Вариант 1 «объемной» надписи</h3>
<div class="container">
<h6 class="hTop yellow">CSS</h6>
<h6 class="unter1 black">CSS</h6>
<h6 class="unter2 gray">CSS</h6>
</div>
<h3>Вариант 2 Текст с тенью</h3>
<div class="container">
<p class="p1 red">тень</p>
<p class="p2 black">тень</p>
<p class="p3 gray">тень</p>
</div>
Скругление углов с помощью CSS3
<div style="border: 1px solid rgb(0, 0, 0);
padding: 20px; margin:20px; width:400px;
border-radius: 9px;
-moz-border-radius: 9px;
-o-border-radius: 9px;
-webkit-border-radius: 9px;
background-color: rgb(204, 204, 204);">
Пользователи Mozilla/Firefox и Safari 3 увидят прямоугольный бокс со скругленными углами.
В IE будет просто прямоугольник.
</div>
Скругление углов 2
<style type="text/css">
body{padding: 20px;background-color: #FFF;
font: 100.01% "Trebuchet MS",Verdana,Arial,sans-serif}
h1,h2,p{margin: 0 10px}
h1{font-size: 250%;color: #FFF}
h2{font-size: 200%;color: #f0f0f0}
p{padding-bottom:1em}
h2{padding-top: 0.3em}
div#nifty{ margin: 0 10%;background: #9BD1FA; width:600px;}
b.rtop, b.rbottom{display:block;background: #FFF}
b.rtop b, b.rbottom b{display:block;height: 1px;
overflow: hidden; background: #9BD1FA}
b.r1{margin: 0 5px}
b.r2{margin: 0 3px}
b.r3{margin: 0 2px}
b.rtop b.r4, b.rbottom b.r4{margin: 0 1px;height: 2px}
</style>
<div id="nifty">
<b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>
<h1>Скругление углов</h1>
<p>Обратите внимание на окантовку этого блока. У него закругленные углы.
Это сделанно без использования картинок. Только за счет использования CSS3.</p>
<b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>
</div>
Меню на CSS3
<style>
.container {
/*margin-left: auto;
margin-right: auto;
margin-top: 30px;*/
width: 800px
}
#nav span {
display: none
}
#nav, #nav ul {
list-style: none outside none;
margin: 0;
padding: 0
}
#nav {
background-color: #f5f5f5;
border-bottom: 5px solid #333;
float: left;
margin-left: 1%;
margin-right: 1%;
position: relative;
width: 98%
}
#nav ul.subs {
background-color: #fff;
box-shadow: 1px 1px 5px rgba(0, 0, 0, .2);
color: #333;
display: none;
left: 0;
padding: 2%;
position: absolute;
top: 54px;
width: 96%
}
#nav > li {
list-style: none;
padding: 0;
min-width: 10px;
border-bottom: 5px solid transparent;
float: left;
margin-bottom: -5px;
text-align: left;
-moz-transition: all 300ms ease-in-out 0s;
-ms-transition: all 300ms ease-in-out 0s;
-o-transition: all 300ms ease-in-out 0s;
-webkit-transition: all 300ms ease-in-out 0s;
transition: all 300ms ease-in-out 0s
}
#nav li a {
display: block;
text-decoration: none;
-moz-transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
-ms-transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
-o-transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
-webkit-transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
white-space: normal
}
#nav > li > a {
color: #333;
display: block;
font-size: 1.3em;
line-height: 49px;
padding: 0 15px;
text-transform: uppercase
}
#nav > li:hover > a, #nav > a:hover {
background-color: #f55856;
color: #fff
}
#nav li.active > a {
background-color: #333;
color: #fff
}
#nav li:hover ul.subs {
display: block
}
#nav ul.subs > li {
display: inline-block;
float: none;
padding: 10px 1%;
vertical-align: top;
width: 33%
}
#nav ul.subs > li a {
color: #777;
line-height: 20px
}
#nav ul li a:hover {
color: #f55856
}
#nav ul.subs > li > a {
font-size: 1.3em;
margin-bottom: 10px;
text-transform: uppercase
}
#nav ul.subs > li li {
float: none;
padding-left: 8px;
-moz-transition: padding 150ms ease-out 0s;
-ms-transition: padding 150ms ease-out 0s;
-o-transition: padding 150ms ease-out 0s;
-webkit-transition: padding 150ms ease-out 0s;
transition: padding 150ms ease-out 0s
}
#nav ul.subs > li li:hover {
padding-left: 15px
}
@media all and (max-width: 980px) {
#nav > li {
float: none;
border-bottom: 0;
margin-bottom: 0
}
#nav ul.subs {
position: relative;
top: 0
}
#nav li:hover ul.subs {
display: none
}
#nav li #s1:target + ul.subs, #nav li #s2:target + ul.subs {
display: block
}
#nav ul.subs > li {
display: block;
width: auto
}
}
</style>
<h1>Меню на чистом CSS3 без javascript</h1>
<br class="clear">
<div class=container>
<ul id=nav>
<li><a href="#">Главная</a></li>
<li><a href="#s1">Меню 1</a>
<span id=s1></span>
<ul class=subs>
<li><a href="#">Заголовок a</a>
<ul>
<li><a href="#">Подменю x</a></li>
<li><a href="#">Подменю y</a></li>
<li><a href="#">Подменю z</a></li>
</ul>
</li>
<li><a href="#">Заголовок b</a>
<ul>
<li><a href="#">Подменю x</a></li>
<li><a href="#">Подменю y</a></li>
<li><a href="#">Подменю z</a></li>
</ul>
</li>
</ul>
</li>
<li class=active><a href="#s2">Меню 2</a>
<span id=s2></span>
<ul class=subs>
<li><a href="#">Заголовок c</a>
<ul>
<li><a href="#">Подменю x</a></li>
<li><a href="#">Подменю y</a></li>
<li><a href="#">Подменю z</a></li>
</ul>
</li>
<li><a href="#">Заголовок d</a>
<ul>
<li><a href="#">Подменю x</a></li>
<li><a href="#">Подменю y</a></li>
<li><a href="#">Подменю z</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Меню 3</a></li>
</ul>
</div>
<br class="clear">
Всевозможные маркеры пунктов списков
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">
<style type="text/css">
ul.a {list-style-type:circle;}
ul.b {list-style-type:disc;}
ul.c {list-style-type:square;}
ol.d {list-style-type:armenian;}
ol.e {list-style-type:cjk-ideographic;}
ol.f {list-style-type:decimal;}
ol.g {list-style-type:decimal-leading-zero;}
ol.h {list-style-type:georgian;}
ol.i {list-style-type:hebrew;}
ol.j {list-style-type:hiragana;}
ol.k {list-style-type:hiragana-iroha;}
ol.l {list-style-type:katakana;}
ol.m {list-style-type:katagana-iroha;}
ol.n {list-style-type:lower-alpha;}
ol.o {list-style-type:lower-greek;}
ol.p {list-style-type:lower-latin;}
ol.q {list-style-type:lower-roman;}
ol.r {list-style-type:upper-alpha;}
ol.s {list-style-type:upper-latin;}
ol.t {list-style-type:upper-roman;}
ol.u {list-style-type:none;}
ol.v {list-style-type:inherit;}
</style>
</head>
<body>
<ul class="a">
<li>Тип - окружности</li>
<li>Чай</li>
<li>Кока Кола</li>
</ul>
<ul class="b">
<li>Тип - диски</li>
<li>Чай</li>
<li>Кока Кола</li>
</ul>
<ul class="c">
<li>Тип - квадраты</li>
<li>Чай</li>
<li>Кока Кола</li>
</ul>
<ol class="d">
<li>Армянский тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="e">
<li>Cjk-идеографический тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="f">
<li>Десятичный тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="g">
<li>Десятичный тип с нулем впереди</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="h">
<li>Грузинский тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="i">
<li>Еврейский тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="j">
<li>Хираганский тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="k">
<li>Хираганский тип 2</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="l">
<li>Катаканский тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="m">
<li>Катаканский тип 2</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="n">
<li>Алфавит в нижнем регистре</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="o">
<li>Греческий алфавит в нижнем регистре</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="p">
<li>Латинский алфавит в нижнем регистре</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="q">
<li>Римский алфавит в нижнем регистре</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="r">
<li>Алфавит в верхнем регистре</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="s">
<li>Латинский алфавит в верхнем регистре</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="t">
<li>Римский алфавит в верхнем регистре</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="u">
<li>None-тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
<ol class="v">
<li>унаследованный тип</li>
<li>Чай</li>
<li>Кока Кола</li>
</ol>
</body>
</html>
Установка изображения в качестве маркера пункта списка
<html>
<head>
<style type="text/css">
ul
{
list-style-type:none;
padding:0px;
margin:0px;
}
li
{
background-image:url(sqpurple.gif);
background-repeat:no-repeat;
background-position:0px 5px;
padding-left:14px;
}
</style>
</head>
<body>
<ul>
<li>Кофе</li>
<li>Чай</li>
<li>Кока Кола</li>
</ul>
</body>
</html>
Добавление градиента
background: -webkit-gradient(linear, left top, left bottom, from(#74b8d7), to(#437fbc)); background: -moz-linear-gradient(top, #74b8d7, #437fbc); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#74b8d7', endColorstr='#437fbc');
Фиксация футера на CSS
#footer {
position:fixed;
left:0px;
bottom:0px;
height:32px;
width:100%;
background:#333;
}
/* IE 6 */
* html #footer {
position:absolute;
top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px');
}
CSS код для multiple backgrounds
#multipleBGs {
background: url(photo1.png),
url(photo2.png),
url(photo3.png)
;
background-repeat: no-repeat,
no-repeat,
repeat-y;
background-position: 0 0,
30px 70px,
right top;
width: 400px;
height: 400px;
border: 1px solid #ccc;
}
Анимируем CSS-градиенты
HTML
<!DOCTYPE html> <html> <head> <script src="http://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script> <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <div></div> </body> </html>
CSS
BODY {
background: #EEE;
padding: 30px;
}
DIV {
height: 200px;
background: linear-gradient(crimson, gold, yellowgreen, teal, crimson);
background-position: 0 0;
border-radius: 30px;
border: 10px solid white;
animation: background 2s infinite alternate;
}
@keyframes background {
100% {
background-position: 0 200px;
}
}
Градиент с плавной сменой цветов
HTML
<!DOCTYPE html> <html> <head> <script src="http://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script> <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <div></div> </body> </html>
CSS
BODY {
background: #EEE;
padding: 30px;
}
DIV {
height: 200px;
background: gold;
box-shadow: 0 -200px 100px -120px crimson inset;
border-radius: 30px;
border: 10px solid white;
animation: background 3s infinite alternate;
}
@keyframes background {
50% {
background: skyblue;
box-shadow: 0 -200px 100px -100px yellowgreen inset;
}
}
Менять цвет неба в зависимости от времени суток
HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class="stage">
<div class="sun"></div>
<div class="grass"></div>
<div class="square"></div>
<div class="round"></div>
</div>
</body>
</html>
CSS
BODY {
margin: 0;
overflow: hidden;
background: black;
}
.stage {
position: relative;
width: 100%;
height: 350px;
overflow: hidden;
background: steelblue;
box-shadow: 0 -400px 300px -300px orangered inset;
animation: sky 15s infinite linear;
}
.sun {
position: absolute;
left: 0;
bottom: -30%;
width: 10em;
height: 10em;
margin-left: -2.5em;
margin-top: 0;
background: orangered;
border-radius: 50%;
box-shadow: 0 0 20px orange;
animation: 15s infinite linear;
animation-name: move, sun-color;
}
.grass {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: url(http://img-fotki.yandex.ru/get/5000/5091629.98/0_7a92d_7ece70d7_XL.png) no-repeat center bottom;
}
@keyframes sky {
0% {
background: darkslateblue;
}
50% {
background: skyblue;
box-shadow: 0 -400px 300px -300px steelblue inset;
}
85% {
background: darkslateblue;
box-shadow: 0 -400px 300px -300px orangered inset;
}
100% {
background: darkslateblue;
}
}
@keyframes move {
0% {
}
10% {
margin-left: -4.5em;
}
20% {
margin-left: -5.5em;
}
30% {
margin-left: -6em;
}
40% {
margin-left: -4.5em;
}
50% {
left: 50%;
bottom: 75%;
width: 5em;
height: 5em;
margin-left: -2.5em;
}
60% {
margin-left: 1.5em;
}
70% {
margin-left: 3.5em;
}
80% {
margin-left: 2.5em;
}
90% {
margin-left: 1em;
}
100% {
left: 98%;
margin-left: -2.5em;
}
}
@keyframes sun-color {
20% {
background: orange;
}
40% {
background: gold;
box-shadow: 0 0 35px gold;
}
60% {
background: yellow;
box-shadow: 0 0 35px yellow;
}
80% {
background: orange;
}
}
Анимированный Background 1
BODY {
background: #F3F3F3;
box-shadow: 0 -200px 100px -120px white inset;
animation: background 13s infinite alternate;
}
@keyframes background {
50% {
background: white;
box-shadow: 0 -200px 100px -100px white inset;
}
}
Анимированный Background 2
BODY {
background: crimson;
box-shadow: 0 -150px 70px -120px teal inset,
0 -220px 70px -120px yellowgreen inset,
0 -280px 70px -120px gold inset;
border-radius: 30px;
animation: background 4s infinite alternate;
}
@keyframes background {
50% {
background: darkviolet;
box-shadow: 0 -140px 70px -120px mediumorchid inset,
0 -210px 70px -120px teal inset,
0 -280px 70px -120px plum inset;
}
}
Box-shadow
HTML
<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <div></div> </body> </html>
CSS
DIV {
width: 150px;
height: 150px;
margin: 3em;
background: white;
border: 1px solid lightgray;
box-shadow: 15px 15px 5px -5px rgba(0,0,0,.2)
}
BG gradient
HTML
DIV {
width: 150px;
height: 150px;
margin: 3em;
background: white;
border: 1px solid lightgray;
box-shadow: 15px 15px 5px -5px rgba(0,0,0,.2)
}
CSS
BODY {
text-align: center;
}
DIV {
position: relative;
display: inline-block;
width: 10em;
height: 10em;
margin: 1em 2em 0;
border: 1px solid #DDD;
}
DIV:before {
position: absolute;
bottom: 0;
left: 0;
right: 0;
content: attr(data-content);
font-size: 1.7em;
text-shadow: 1px 1px 2px hsla(20,100%,50%,.7),
-1px -1px 2px hsla(20,100%,50%,.7);
color: white;
}
.bg-gradient {
background: linear-gradient(orangered, gold);
animation: bgcolor 3s infinite;
border: 3px solid orangered;
}
@keyframes bgcolor {
50% {
background: linear-gradient(purple, yellowgreen);
border: 3px solid purple;
}
}
.bg-shadow {
background: gold;
box-shadow: 0 10em 5em -5em orangered inset;
border: 3px solid orangered;
animation: shadow 3s infinite;
}
@keyframes shadow {
50% {
background: pink;
box-shadow: 0 10em 5em -5em purple inset;
border: 3px solid purple;
}
}
3D cube
HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class="container">
<div class="back side"></div>
<div class="left side"></div>
<div class="right side"></div>
<div class="top side"></div>
<div class="bottom side"></div>
<div class="front side"></div>
</div>
</body>
</html>
CSS
BODY {
perspective: 500px;
perspective-origin: center -5em;
}
.container {
margin: 3em auto 0;
width: 10em;
height: 10em;
border: 2px dotted white;
transform-style: preserve-3d;
opacity: .7;
animation: rotate 10s infinite linear;
}
.container:before,
.container:after {
content: "";
display: block;
position: absolute;
width: 10em;
height: 10em;
border: 2px dotted white;
}
.container:before {
transform: rotateX(90deg);
}
.container:after {
transform: rotatey(90deg);
}
.side {
position: absolute;
width: 10em;
height: 10em;
border: 1px solid white;
opacity: .7;
}
.back {
transform: translateZ(-5em);
background: orange;
}
.front {
transform: translateZ(5em);
background: gold;
}
.top {
transform: translateY(-5em) rotateX(90deg);
background: skyblue;
}
.bottom {
transform: translateY(5em) rotateX(90deg);
background: steelblue;
}
.left {
transform: translateX(-5em) rotateY(90deg);
background: lightgreen;
}
.right {
transform: translateX(5em) rotateY(90deg);
background: yellowgreen;
}
@keyframes rotate {
100% {
transform: rotateY(360deg);
}
}
Background — тетрадный лист в линейку:
HTML {
height: 100%;
}
BODY {
background: linear-gradient(90deg,
rgba(255, 255, 255, 0) 1.8em, rgba(135, 206, 235, .5) 2em)
4em 0 repeat-y,
linear-gradient(
rgba(255,255,255, 0) 1.9em, rgba(0, 0, 0, .15) 2em)
0 0;
background-size: 2em 2em;
background-color: ivory;
font: 16px/2 'Trebuchet MS', Verdana, sans-serif;
}
P {
margin: 2.5em 3em 1em 8em;
}
Background — тетрадный лист в клетку:
HTML {
height: 100%;
}
BODY {
background: linear-gradient(
rgba(255,255,255, 0) .9em, rgba(0, 0, 0, .15) 1em)
0 0,
linear-gradient(90deg,
rgba(255,255,255, 0) .9em, rgba(0, 0, 0, .15) 1em)
0 0;
background-size: 1em 1em;
background-color: ivory;
font: italic 16px/2 'Trebuchet MS', Verdana, sans-serif;
}
P {
margin: 2.55em 3em 1em;
}
Background — Радиальный градиент
HTML {
height: 100%;
}
BODY {
background: radial-gradient(gold, orangered);
font: 16px/1.4 'Trebuchet MS', Verdana, sans-serif;
}
Background — Радиальный градиент (круг)
HTML {
height: 100%;
}
BODY {
background: radial-gradient(circle, skyblue 50%, steelblue 70%);
font: 16px/1.4 'Trebuchet MS', Verdana, sans-serif;
}
Background — Радиальный градиент (с одной из сторон)
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Gradients</title>
</head>
<body>
<ul>
<li class="top-left">at top left</li><li class="top">at top</li><li class="top-right">at top right</li>
<li class="clear"></li>
<li class="left">at left</li><li class="center">at center</li><li class="right">at right</li>
<li class="clear"></li>
<li class="bottom-left">at bottom left</li><li class="bottom">at bottom</li><li class="bottom-right">at bottom right</li>
</ul>
</body>
</html>
CSS
HTML {
height: 100%;
}
BODY {
background: white;
text-align: center;
font: 16px/1 'Trebuchet MS', Verdana, sans-serif;
}
UL {
display: inline-block;
width: 24.8em;
padding: 0;
list-style: none;
}
LI {
display: inline-block;
vertical-align: top;
width: 8em;
height: 8em;
border: 1px solid #FFF;
border-radius: 5px;
vertical-align: middle;
text-align: center;
text-shadow: 0 0 5px rgba(0,0,0,.9);
color: #FFF;
}
LI:before {
content: "";
display: inline-block;
height: 8em;
vertical-align: middle;
}
.clear {
display: block;
width: 100%;
height: 0;
}
.top,
.center,
.bottom {
margin: 0 2px;
}
.top {
background: radial-gradient(at top, purple, crimson, orangered, gold);
}
.right {
background: radial-gradient(at right, purple, crimson, orangered, gold);
}
.bottom {
background: radial-gradient(at bottom, purple, crimson, orangered, gold);
}
.left {
background: radial-gradient(at left, purple, crimson, orangered, gold);
}
.center {
background: radial-gradient(at center, purple, crimson, orangered, gold);
}
.top-left {
background: radial-gradient(at top left, purple, crimson, orangered, gold);
}
.top-right {
background: radial-gradient(at top right, purple, crimson, orangered, gold);
}
.bottom-left {
background: radial-gradient(at bottom left, purple, crimson, orangered, gold);
}
.bottom-right {
background: radial-gradient(at bottom right, purple, crimson, orangered, gold);
}
То же самое, упрощённое (только CSS) :
HTML {
height: 100%;
}
BODY {
background: radial-gradient(at top, black, gray, lightgray, white);
font: 16px/1.4 'Trebuchet MS', Verdana, sans-serif;
}
Линейные градиенты
Простой
HTML {
height: 100%;
}
BODY {
background: linear-gradient(to top,orangered, gold);
}
разные направления
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Gradients</title>
</head>
<body>
<ul>
<li class="top-left">to top left</li><li class="top">to top</li><li class="top-right">to top right</li>
<li class="clear"></li>
<li class="left">to left</li><li class="center"></li><li class="right">to right</li>
<li class="clear"></li>
<li class="bottom-left">to bottom left</li><li class="bottom">to bottom</li><li class="bottom-right">to bottom right</li>
</ul>
</body>
</html>
CSS
HTML {
height: 100%;
}
BODY {
background: white;
text-align: center;
font: 16px/1 'Trebuchet MS', Verdana, sans-serif;
}
UL {
display: inline-block;
width: 24.8em;
padding: 0;
list-style: none;
}
LI {
display: inline-block;
vertical-align: top;
width: 8em;
height: 8em;
border: 1px solid #FFF;
border-radius: 5px;
vertical-align: middle;
text-align: center;
text-shadow: 0 0 5px rgba(0,0,0,.9);
color: #FFF;
}
LI:before {
content: "";
display: inline-block;
height: 8em;
vertical-align: middle;
}
.clear {
display: block;
width: 100%;
height: 0;
}
.top,
.center,
.bottom {
margin: 0 2px;
}
.top {
background: linear-gradient(to top, purple, crimson, orangered, gold);
}
.right {
background: linear-gradient(to right, purple, crimson, orangered, gold);
}
.bottom {
background: linear-gradient(to bottom, purple, crimson, orangered, gold);
}
.left {
background: linear-gradient(to left, purple, crimson, orangered, gold);
}
.top-left {
background: linear-gradient(to top left, purple, crimson, orangered, gold);
}
.top-right {
background: linear-gradient(to top right, purple, crimson, orangered, gold);
}
.bottom-left {
background: linear-gradient(to bottom left, purple, crimson, orangered, gold);
}
.bottom-right {
background: linear-gradient(to bottom right, purple, crimson, orangered, gold);
}
Border-image
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<img src="http://img-fotki.yandex.ru/get/3102/yoksel.31/0_1d0a3_1b360496_M.jpg" alt="" class="indian">
</body>
</html>
CSS
BODY {
background: white;
text-align: center;
font-size: 10px;
}
.indian {
border: 90px solid transparent;
border-image: url(http://img-fotki.yandex.ru/get/9165/5091629.99/0_7eb49_5c917238_XL.png) 14% 20% stretch round;
}
Самый короткий способ задать изображение для рамки выглядит вот так:
HTML
<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <img src="http://img-fotki.yandex.ru/get/3102/yoksel.31/0_1d0a3_1b360496_M.jpg" alt="" class="border-image"> </body> </html>
CSS
BODY {
background: white;
text-align: center;
font-size: 10px;
}
.border-image {
margin-top: 2em;
border: 60px dashed transparent;
border-image: url("http://img-fotki.yandex.ru/get/6730/5091629.9a/0_7eb4e_e27786d4_XL.png") 25% round;
}
Для border обязательно нужно задать толщину и стиль рамки. Цвет — опционально, но рамку именно такого цвета увидят пользователи, браузеры которых не поддерживают border-image. По умолчанию это будет цвет текста. Можно задавать transparent — прозрачный.
Для border-image обязательно задавать изображение (border-image-source), размер угловой части (border-image-slice) и повторение картинки (border-image-repeat).
Эффект расходящихся лучей:
HTML
<div class="wrapper">
<h1 class="text">Magic rays</h1>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
CSS
@import url(http://fonts.googleapis.com/css?family=Lobster);
HTML, BODY {
height: 100%;
}
BODY {
margin: 0;
overflow: hidden;
background: lightgray;
background: radial-gradient(circle,white 15em, lightgray 35em);
background-size: cover;
font-size: 10px;
}
.wrapper {
position: relative;
height: 100%;
}
.text {
position: relative;
z-index: 1;
position: absolute;
left: -1em;
right: -1em;
top: -1em;
bottom: -1em;
margin: auto;
height: 1em;
font: 6em/1 Lobster, Georgia, cursive;
text-align: center;
text-shadow: -1px -1px #FFF,
-2px -2px #FFF,
-1px 1px #FFF,
-2px 2px #FFF,
1px 1px #FFF,
2px 2px #FFF,
1px -1px #FFF,
2px -2px #FFF,
-3px -3px 2px #CCC,
-3px 3px 2px #CCC,
3px 3px 2px #CCC,
3px -3px 2px #CCC;
color: darkgrey;
transition: all .7s;
}
H1:hover {
color: lightgray;
}
UL {
position: absolute;
left: -1em;
right: -1em;
top: -1em;
bottom: -1em;
margin: auto;
padding: 0;
width: 0;
height: 0;
list-style: none;
animation: 10s rotate infinite linear;
}
LI,
LI:before,
LI:after {
position: absolute;
border: 0 solid transparent;
border-width: 1.2em 20em;
border-color: transparent lightgray;
width: 0;
height: 0;
font-size: 20px;
}
LI {
left: -20em;
top: 50%;
margin-top: -1.2em;
transform: rotate(.1deg);
}
LI:before,
LI:after {
left: -20em;
top: -1.2em;
display: block;
content: "";
}
LI:before {
transform: rotate(60deg);
}
LI:after {
transform: rotate(-60deg);
}
LI:nth-child(2){
transform: rotate(15deg);
}
LI:nth-child(3){
transform: rotate(30deg);
}
LI:nth-child(4){
transform: rotate(45deg);
}
@keyframes rotate {
100% {
transform: rotate(360deg);
}
}
Эффект расходящихся лучей 2:
HTML
<div class="wrapper">
<h1 class="text">Magic rays</h1>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
CSS
@import url(http://fonts.googleapis.com/css?family=Lobster);
HTML, BODY {
height: 100%;
}
HTML, BODY {
height: 100%;
}
BODY {
margin: 0;
overflow: hidden;
background: hsl(200, 100%, 70%);
background: radial-gradient(white 100px, hsl(200, 100%, 70%) 50em);
background-size: cover;
font-size: 10px;
}
.wrapper {
position: relative;
height: 100%;
}
.text {
position: relative;
z-index: 1;
position: absolute;
left: -1em;
right: -1em;
top: -1em;
bottom: -1em;
margin: auto;
height: 1em;
font: 6em/1 Lobster, Georgia, cursive;
text-align: center;
text-shadow: -1px -1px #FFF,
-2px -2px #FFF,
-1px 1px #FFF,
-2px 2px #FFF,
1px 1px #FFF,
2px 2px #FFF,
1px -1px #FFF,
2px -2px #FFF,
-3px -3px 2px #CCC,
-3px 3px 2px #CCC,
3px 3px 2px #CCC,
3px -3px 2px #CCC;
color: hsl(200, 100%, 75%);
transition: all .7s;
}
.text:hover {
color: hsl(200, 100%, 60%);
}
UL {
position: absolute;
left: -1em;
right: -1em;
top: -1em;
bottom: -1em;
margin: auto;
padding: 0;
width: 0;
height: 0;
list-style: none;
animation: 5s rotate infinite linear;
}
LI,
LI:before,
LI:after {
position: absolute;
border: 0 solid transparent;
border-width: 2em 20em;
width: 1px;
height: 1px;
font-size: 30px;
box-shadow: 0 0 2em .5em white;
}
LI {
left: -20em;
top: 50%;
margin-top: -2em;
transform: rotate(.1deg);
}
LI:before,
LI:after {
left: -20em;
top: -2em;
display: block;
content: "";
}
LI:before {
transform: rotate(60deg);
}
LI:after {
transform: rotate(-60deg);
}
LI:nth-child(2){
transform: rotate(15deg);
}
LI:nth-child(3){
transform: rotate(30deg);
}
LI:nth-child(4){
transform: rotate(45deg);
}
@keyframes rotate {
100% {
transform: rotate(90deg);
}
}

