CSS3
CSS3
History of CSS
CSS level 1 – original CSS
CSS level 2
CSS level 2 Revision 1 (CSS2.1) – up to CSS2.1 monolithic
structure
CSS level 3 – specification structured in modules
Modules can evolve independently
Few modules have reached the W3C recommendation status,
but many are implemented in browsers
div {
columns: 40px 2;
}
Borders
border-radius : (<length> | <percent>) {1,4} /
(<length> | <percent>) {1,4}
create rounded corners; there are two radix values for each corner : top-
left, top-right, bottom-right, bottom-left
ex. div { border-radius : 10px 10px 20px 20px / 5px 5px 10px 10px }
box-shadow : h-shadow v-shadow blur spread color
inset
adds a inner/outer shadow to a box;
ex. div { box-shadow : 2px 2px 5px #eeffdd }
border-image : source slice width outset repeat
source=image used for border; slice=4 inward offsets of the border image
for top, bottom, left and right sides; width=4 widths of the border image
for top, bottom, left and right sides; outset=4 values, the amount the
border image extends outside the border of the box
Background and sprites
CSS3 allows to have several background images for an
element
Sprites are several images contained in one image
which can individually be used as backgrounds by
setting different values for background-position; see
example..
Text shadow
text-shadow : h-shadow v-shadow blur color;
Ex.: div {
text-shadow: 2px 2px 4px #ff00dd;
}
CSS flexbox display
allows the contents of a container to be displayed in a
flexible grid (organized in rows and/or columns)
<div class=“flexdiv”>
<div>1</div>
<div>2</div>
</div>
.flexdiv {
display: flex;
flex-direction: column | column-reverse | row | row-reverse;
flex-wrap: nowrap | wrap | wrap-reverse;
justify-content: center | flex-start | flex-end; // align horizontally
align-items: center | flex-start | flex-end; // align vertically
}
Beyond CSS : CSS preprocessors
using functions, variables, inheritance, code
reusability, operators, if, loops in CSS ?
extend CSS syntax (compiled to standard CSS by a
preprocessor written in node.js, ruby etc.)
Stylus
Compass
Less
Sass
CSS preprocessors, example
(less)
@font-size: 16px;
.bordered (@width) {
border: @width solid #ddd;
&:hover {
border-color: #999;
}
}
h1 { .bordered(5px);
font-size: @font-size;
}
Responsive web design
Document should look good on any device (desktop,
tablet, phone)
Use CSS to shrink, enlarge, hide or move html content
in order to look good on any screen
Setting viewport:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- sets the width of the page to follow the screen width of the device