h1 {
color: red;
}
selector {
property: value;
}
@import (...} /* import external css */
@media {...} /* media queries */
@font-face {...} /* web font declaration */
@keyframes {...} /* animation */
body {
font-family: Helvetica, Arial, sans-serif;
}
<html>
<head>...<head>
<body>
<h1>...</h1>
<p>...</p>
</body>
</html>
Selector | Example | Specificity |
element | <div> | 0-0-1 |
class | .class-a | 0-1-0 |
id | #id-b | 1-0-0 |
.box_scale {
-webkit-transform: scale(0.8); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: scale(0.8); /* IE 9 */
transform: scale(0.8); /* Firefox 16+, IE 10+, Opera */
}
not as good way to write styles
header > nav > ul > li > a {
display: inline-block;
font-family: Helvetica, Arial, sans-serif;
font-weight: 600;
font-size: 1.2em;
line-height: .8;
margin-left: .5em;
margin-right: .5em;
padding-left: .25em;
padding-right: .25em;
}
better way to write styles
.navitem {
display: inline-block;
margin-left: .5em;
margin-right: .5em;
padding-left: .25em;
padding-right: .25em;
}
.button {
font-family: Helvetica, Arial, sans-serif;
font-size: 1.2em;
font-weight: 600;
line-height: .8;
}
.block__element--modifier { ... }
.title {
color: dimgray;
font-family: Helvetica, Arial, sans-serif;
font-size: 2em;
}
@media screen and (min-width: 20em) {
.title {
font-size: 4em;
}
}
@media screen and (max-width: 19.99em)
.title {
color: dimgray;
font-family: Helvetica, Arial, sans-serif;
font-size: 2em;
}
}
@media screen and (min-witdh: 20em) and (max-width: 39.99em)
.title {
color: dimgray;
font-family: Helvetica, Arial, sans-serif;
font-size: 4em;
}
}
@media screen and (min-witdh: 40em) and (max-width: 60em)
.title {
color: dimgray;
font-family: Helvetica, Arial, sans-serif;
font-size: 6em;
}
}
.title {
color: dimgray;
font-family: Helvetica, Arial, sans-serif;
font-size: 2em;
}
@media screen and (min-width: 20em) {
.title {
font-size: 4em;
}
}
@media screen and (min-width: 40em) {
.title {
font-size: 6em;
}
}
.thing {
margin: 0 1em;
}
.thing {
margin-left: 1em;
margin-right: 1em;
}
.subheading {
color: red;
font-size: 2em;
font-weight: 100;
}