author: | Pierre-Antoine Champin |
---|---|
date: | 2012 |
address: | Département Informatique, IUT Lyon 1 |
In the <head> element, either as an external stylesheet:
<head> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head>
or as an internal (embeded) stylesheet:
<head> <style type="text/css"> /* your CSS here */ </style> </head>
Have a look at http://champin.net/enseignement/web/styles/ .
em { font-style: italic }
em { font-style: italic } em { color: blue } cite { font-style: italic } cite { color: blue }
em, cite { font-style: italic; color: blue }
font-style
:
font-weight
:
font-variant
:
font-family
:
font-size
:
Either the font must be installed on the system (fragile!), or declared as followed:
@font-face { font-family: MyNiftyFont; src: url('http://example.org/nifty-font.ttf'), url('http://example.org/nifty-font.eot'); }
Note
It may be necessary to provide the font in several formats in order to maximize compatibility with various browsers.
Will work in any browser, but appearance may vary:
Good practice, when using specific fonts, is to provide a generic fallback:
font-family: MyNiftyFont, Times New Roman, serif
Font size is typically represented in points
body { font-size: 12pt ; }
or relatively to the font size of the enclosing element:
h1 { font-size: 150% ; }
CSS also provides a number of other units, either absolute (cm, mm, px...) or relative (em, ex...).
text-decoration
: text-transform
: text-align
: color
:
background-color
:
em { color: #f00 } /* #rgb */ em { color: #ff0000 } /* #rrggbb */ em { color: rgb(255,0,0) } em { color: rgb(100%, 0%, 0%) }
The CSS boxing model:
The margin and padding properties can be used as a shortcut, or their *-top, *-bottom, *-left and *-right variants can be used for more control
p { padding: 1em; margin-top: 0.5cm ; margin-bottom 0.7cm; margin-left: 2cm; margin-right: 1cm; }
NB: the em unit equals the current font-size
border-width
: a length and a unit
border-style
:
border-color
: a color
The three can also be combined (in that order) withing property border.
border: 1px solid red ;
The size of a box can be set with the width and height attribute (using either relative or absolute lengths).
For example, this paragraph has ``width: 50%``, which makes it occupy half of the width of the page.
Sizes can also be more loosely constrained with the min-width, min-height, max-with and max-height attributes.
Some images (or inserts) <img src="img/monalisa.jpg"> are outside the normal flow of text. Instead they “float” on the right (or left) of the text.
will normaly be rendered as
Some images (or inserts) are outside the normal flow of text. Instead they “float” on the right (or left) of the text.
With the following CSS,
img { float: right; /* can also be left */ }
you will get:
Some images (or inserts) are outside the normal flow of text. Instead they “float” on the right (or left) of the text.
More complex selectors can be used to select elements based on their context:
p em { /* applies to any <em> inside a <p> — even indirectly */ } p>em { /* applies to any <em> directly inside a <p> */ } h1+p { /* applies to any <p> directly following a <h1> */ }
HTML allows the class and id attribute on any tag:
<ul id="contents">...</ul> <p class="summary funny">...</p>
CSS allows to select elements based on their id or class, even regardless of their tag.
p.summary { /* any <p> with class 'summary' */ } .funny { /* any element with class 'funny' */ } p#contents { /* the 'contents' element if it is a <p> */ } #contents em { /* any <em> in the 'contents' element */ }
Considering:
em { font-style: italic } .summary em { font-style: normal; font-weight: bold }
How should the following look?
<p class="summary">This summary is <em>short</em>.</p>
The HTML in last slide should look like:
This summary is short.
Intuitively, the most specific rules takes precedence here.
CSS priority (“cascading”) rules are complex, but usually match the intuition/intent of the author:
→ (most of the time) they do what one would expect.
Pseudo-classes are automatically attached to elements based on some features they have:
a:link { /* matches any unvisited link */ } a:visited { /* matches any visited link */ } :hover { /* matches any element when the mouse pointer is hovering on it */ } li:first-child { /* matches the first <li> of a list */ } li:last-child { /* can't you guess? */ }
Pseudo-elements are parts of a text that is not explicitly tagged, but can be assigned a specific style.
h1:first-letter { /* 1st letter of any <h1> */ } h1+p:first-line { /* 1st line of any <p> following a <h1> */ }
(toutes les pages de ces deux derniers sont des présentations différentes pour le même HTML!)
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |