author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Sat, 28 May 2016 00:33:40 +0300 | |
changeset 1968 | 227261ce4ebb |
parent 1924 | 46a080141f3a |
child 2065 | 178383c735a5 |
permissions | -rw-r--r-- |
1045 | 1 |
.. -*- coding: utf-8; -*- |
2 |
||
1920 | 3 |
===== |
4 |
CSS |
|
5 |
===== |
|
1045 | 6 |
.. contents:: |
1905
fba288d59662
Include only local subsections into TOC. This prevent duplication of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1789
diff
changeset
|
7 |
:local: |
1045 | 8 |
|
1920 | 9 |
Adding CSS to HTML |
10 |
================== |
|
1045 | 11 |
|
1919
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
12 |
Include to CSS file in ``head`` tag:: |
1045 | 13 |
|
14 |
<html> |
|
15 |
<head> |
|
16 |
<link href="path-to.css" rel="stylesheet" type="text/css"> |
|
17 |
</head> |
|
18 |
... |
|
19 |
<html> |
|
20 |
||
1919
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
21 |
or embed style into ``style`` tag (that tag valid only in ``head`` tag):: |
1045 | 22 |
|
23 |
<head> |
|
24 |
<style type="text/css"> |
|
25 |
h1 {border-width: 1; border: solid; text-align: center} |
|
26 |
</style> |
|
27 |
</head> |
|
28 |
||
1919
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
29 |
HTML 5 standard doesn't require ``type`` attribute, above example may be |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
30 |
rewritten into:: |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
31 |
|
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
32 |
<head> |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
33 |
<style> |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
34 |
h1 {border-width: 1; border: solid; text-align: center} |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
35 |
</style> |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
36 |
</head> |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
37 |
|
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
38 |
To change style of specific tag embedding into ``style`` attribute (style syntax |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
39 |
doesn't use selectors!):: |
1045 | 40 |
|
41 |
<b style="color: blue; font-family: ariel">Welcome!</b> |
|
42 |
||
1920 | 43 |
Selectors |
44 |
========= |
|
1389
4ab574ec7067
Add links to standard.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
45 |
:: |
1045 | 46 |
|
47 |
tag {} |
|
48 |
.class {} |
|
49 |
#id {} для id разрешены символы |
|
50 |
* {} - любой элемент |
|
51 |
||
52 |
tag tag1 {} - выбор tag1, у которых есть предок tag |
|
53 |
tag > tag {} - выбор дочернего элемента |
|
54 |
tag + tag {} - выбор соседних элементов |
|
55 |
tag ~ tag {} - выбор любого соседа |
|
56 |
||
57 |
[attr] {} |
|
1433
933af00eae13
Selector by several attributes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1408
diff
changeset
|
58 |
[attr1][attr2] {} |
1045 | 59 |
[attr="..."] {} |
60 |
[attr~="..."] {} - присутствует слово ... в поле атрибута |
|
61 |
[attr*="..."] {} - присутствует набор символов ... в поле атрибута |
|
62 |
[attr^="..."] {} - начинается с ... в поле атрибута |
|
63 |
[attr$="..."] {} - заканчивается на ... в поле атрибута |
|
64 |
tag [attr|="..."] {} |
|
65 |
||
66 |
:link - не посещенные ссылки |
|
67 |
:visited - посещенные ссылки |
|
68 |
:active - нажатие на левую клавишу мыши на элементе |
|
69 |
:hover - назначать при наведении |
|
70 |
:focus - при фокусировке элемента |
|
71 |
:first-child - первый подэлемент |
|
72 |
:last-child - последний подэлемент |
|
73 |
||
74 |
:first-line |
|
75 |
:first-letter - выбрать первую букву (не приминимо к inline элементам) |
|
76 |
:before{content:"..."}, ставит перед контентом элементов строку xxx (можно |
|
77 |
использовать счетчики) |
|
78 |
:after{} - тоже, что и before, только ставит текст после контента тега |
|
79 |
||
1389
4ab574ec7067
Add links to standard.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
80 |
See: |
4ab574ec7067
Add links to standard.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
81 |
|
4ab574ec7067
Add links to standard.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
82 |
* http://www.w3.org/TR/CSS2/selector.html |
4ab574ec7067
Add links to standard.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
83 |
* http://www.w3.org/TR/css3-selectors/#selectors |
4ab574ec7067
Add links to standard.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
84 |
|
1920 | 85 |
CSS include statement |
86 |
===================== |
|
1408
085cde50fc0c
CSS include statement.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1389
diff
changeset
|
87 |
:: |
085cde50fc0c
CSS include statement.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1389
diff
changeset
|
88 |
|
085cde50fc0c
CSS include statement.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1389
diff
changeset
|
89 |
@import url("common.css"); |
085cde50fc0c
CSS include statement.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1389
diff
changeset
|
90 |
|
1919
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
91 |
Include statment supports media query syntax:: |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
92 |
|
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
93 |
@import url(print.css) print; |
83069b397c1f
Include statment supports media query syntax
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
94 |
|
1920 | 95 |
Default style for HTML elements |
96 |
=============================== |
|
1461
f030b717a402
Default style for HTML elements.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1433
diff
changeset
|
97 |
|
f030b717a402
Default style for HTML elements.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1433
diff
changeset
|
98 |
* http://www.w3.org/TR/CSS2/sample.html |
f030b717a402
Default style for HTML elements.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1433
diff
changeset
|
99 |
|
1920 | 100 |
Media queries |
101 |
============= |
|
1045 | 102 |
|
1924
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
103 |
Syntax for media queries inside CSS file is:: |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
104 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
105 |
@media print { ... } |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
106 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
107 |
@media (min-width: 400px) and (max-width: 600px) { ... } |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
108 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
109 |
@import url(print.css) print; |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
110 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
111 |
It is possible to link to CSS file with media queries with ``media`` attribute:: |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
112 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
113 |
<link rel="stylesheet" media="(max-width: 640px)" href="max-640px.css"> |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
114 |
<link rel="stylesheet" media="(min-width: 640px)" href="min-640px.css"> |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
115 |
<link rel="stylesheet" media="(orientation: portrait)" href="portrait.css"> |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
116 |
<link rel="stylesheet" media="(orientation: landscape)" href="landscape.css"> |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
117 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
118 |
Possible predicates: |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
119 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
120 |
``(min-width: VAL)`` |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
121 |
Rules applied for any browser width over the value defined in the query. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
122 |
``(max-width: VAL)`` |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
123 |
Rules applied for any browser width below the value defined in the query. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
124 |
``(min-height: VAL)`` |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
125 |
Rules applied for any browser height over the value defined in the query. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
126 |
``(max-height: VAL)`` |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
127 |
Rules applied for any browser height below the value defined in the query. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
128 |
``(orientation=portrait)`` |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
129 |
Rules applied for any browser where the height is greater than or equal to the width. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
130 |
``(orientation=landscape)`` |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
131 |
Rules for any browser where the width is greater than the height. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
132 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
133 |
See: |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
134 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
135 |
https://developers.google.com/web/fundamentals/design-and-ui/responsive/fundamentals/use-media-queries |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
136 |
Use CSS media queries for responsiveness |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
137 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
138 |
Viewport |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
139 |
======== |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
140 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
141 |
Specs: |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
142 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
143 |
https://www.w3.org/TR/css-device-adapt/ |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
144 |
Unpublished: CSS Device Adaptation Module Level 1 |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
145 |
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
146 |
``viewport`` attribute in ``meta`` tag. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
147 |
https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
148 |
Firefox mobile support for viewport. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
149 |
https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
150 |
Original viewport specs. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
151 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
152 |
Compatibility: |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
153 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
154 |
http://www.quirksmode.org/mobile/tableViewport.html |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
155 |
Compatibility table. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
156 |
http://viewportsizes.com/ |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
157 |
Device table with viewport width. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
158 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
159 |
Articles: |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
160 |
|
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
161 |
http://www.quirksmode.org/mobile/viewports.html |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
162 |
How viewports and the widths of various important elements work, such as the |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
163 |
``<html>`` element, as well as the window and the screen. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
164 |
http://www.quirksmode.org/mobile/viewports2.html |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
165 |
How viewports and the widths of various important elements work, such as the |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
166 |
``<html>`` element, as well as the window and the screen. |
46a080141f3a
Media queries, Viewport
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1921
diff
changeset
|
167 |
|
1920 | 168 |
CSS compilers |
169 |
============= |
|
1535
e499cb39b573
CSS frameworks. CSS compilers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1461
diff
changeset
|
170 |
|
e499cb39b573
CSS frameworks. CSS compilers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1461
diff
changeset
|
171 |
http://lesscss.org/ |
e499cb39b573
CSS frameworks. CSS compilers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1461
diff
changeset
|
172 |
LESS extends CSS with dynamic behavior such as variables, |
e499cb39b573
CSS frameworks. CSS compilers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1461
diff
changeset
|
173 |
mixins, operations and functions. |
e499cb39b573
CSS frameworks. CSS compilers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1461
diff
changeset
|
174 |
http://sass-lang.com/ |
e499cb39b573
CSS frameworks. CSS compilers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1461
diff
changeset
|
175 |
Sass is the most mature, stable, and powerful professional grade |
e499cb39b573
CSS frameworks. CSS compilers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1461
diff
changeset
|
176 |
CSS extension language in the world. |
e499cb39b573
CSS frameworks. CSS compilers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1461
diff
changeset
|
177 |
|
1920 | 178 |
CSS browser support |
179 |
=================== |
|
180 |
||
181 |
* http://www.quirksmode.org/css/contents.html |
|
182 |
* http://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28CSS%29 |
|
183 |
* http://www.css3.info/modules/selector-compat/ |
|
184 |
||
185 |
Editor support |
|
186 |
============== |
|
187 |
||
188 |
Emacs |
|
189 |
----- |
|
190 |
:: |
|
191 |
||
192 |
$ sudo apt-get install css-mode |
|
193 |
||
194 |
Graphical editor |
|
195 |
---------------- |
|
196 |
:: |
|
197 |
||
198 |
$ sudo apt-get install cssed |