Is a style sheet language used for describing the presentation of a document written in a markup language. Most often used to set the visual style of web pages and user interfaces written in HTML and XHTML
CSS is used to describe the appearance of the webpage
Haakon Wion Lee - scientist, specialist in the field of computer science who proposed CSS in 1994
Inheritance
Principles:
Cascading
CSS has a very straightforward syntax. Your CSS is divided into rules. Each rule has two parts: a selector and one or more declarations (each of which has a property and a value). Here's an example rule :
The selector does exactly what it sounds like: it selects certain parts of your HTML document. There're a few ways for you to do this. The simplest is to simply u se a tag name (this'll select all the <h1> tags in your document):
h1 {
*put your declarations here
}
Another way is to use IDs and Classes. This is useful if you want to only select one or a few of a certain tag. They both correspond to special attributes that you can use on any tag.
Use IDs to uniquely identify a single tag:
<div id="myfavdiv">Hiyya!</div>
And select them in CSS with a hash (#) followed by the ID:
#myfavdiv {
*declarations go here*
}
Use classes to identify groups of tags:
<div class="smalldivs">itsy-bitsy</div>
<div class="smalldivs">tiny</div>
And select them with a period (.) followed by the class:
.smalldivs {
*declarations go here*
}
Once you've selected a set of elements, use declarations to change their visual properties. Declarations come after a selector, and are enclosed in curly-brackets {like these}. Each declaration has the format:
property: value;
Don't forget that semi-colon! It'll lead to big problems later on!
em
Relative to the font-size of the element (2em means 2 times the size of the current font)
vw
Relative to font-size of the root element
rem
Relative to 1% of the width of the viewport
vh
Relative to 1% of the height of the viewport
%
Take length in percent
Relative length units specify a length relative to another length property. Relative length units scales better between different rendering mediums.
The absolute length units are fixed and a length expressed in any of these will appear as exactly that size.
cm
centimeters
mm
millimeters
in
inches (1in = 96px = 2.54cm)
points (1pt = 1/72 of 1in)
pt
px
pixels (1px = 1/96th of 1in). Pixels (px) are relative to the viewing device
Colors are displayed combining RED, GREEN, and BLUE light.
Color | Color HEX | Color RGB |
---|---|---|
#000000 | rgb(0,0,0) | |
#FF0000 | rgb(255,0,0) | |
#00FF00 | rgb(0,255,0) | |
#0000FF | rgb(0,0,255) | |
#FFFF00 | rgb(255,255,0) | |
#00FFFF | rgb(0,255,255) | |
#FF00FF | rgb(255,0,255) | |
#C0C0C0 | rgb(192,192,192) | |
#FFFFFF | rgb(255,255,255) |
Do NOT start a selector name with a number!
The element selector selects elements based on the element name.
You can select all <p> elements on a page like this: (all <p> elements will be center-aligned, with a red text color)
The class selector selects elements with a specific class attribute
You can group the selectors, to minimize the code
To group selectors, separate each selector with a comma
Why Validate?
http://jigsaw.w3.org/css-validator/ - Validator
CSS font properties define the font family, boldness, size, and the style of a text.
Difference Between Serif and Sans-serif Fonts
In CSS, there are two types of font family names:
Generic family | Font family | Description |
---|---|---|
Serif |
Times New Roman Georgia |
Serif fonts have small lines at the ends on some characters |
Sans-serif |
Arial Verdana |
"Sans" means without - these fonts do not have the lines at the ends of characters |
Monospace |
Courier New Lucida Console |
All monospace characters have the same width |
The font-style property is mostly used to specify italic text.
This property has three values:
The font-size property sets the size of the text
In a small-caps font, all lowercase letters are converted to uppercase letters. However, the converted uppercase letters appears in a smaller font size than the original uppercase letters in the text.
normal
The browser displays a normal font. This is default
small-caps
The browser displays a small-caps font
The font-weight property sets how thick or thin characters in text should be displayed.
normal
Defines normal characters. This is default
bold
normal
lighter
Defines thick characters
Defines thicker characters
Defines lighter characters
100
200
300
400
500
600
700
800
900
Defines from thin to thick characters. 400 is the same as normal, and 700 is the same as bold
CSS gives you precise control over typography in your Web pages, allowing you to set parameters such as the spacing between lines, words and even letters, and the alignment and indenting of text.
The color property is used to set the color of the text.
With CSS, a color is most often specified by:
The text-decoration property is used to set or remove decorations from text
The text-transform property is used to specify uppercase and lowercase letters in a text.
The text-indent property is used to specify the indentation of the first line of a text.
The direction property specifies the text direction/writing direction.
ltr
The writing direction is left-to-right. This is default
rtl
The writing direction is right-to-left
The letter-spacing property increases or decreases the space between characters in a text.
The text-shadow property adds shadow to text.
text-shadow: h-shadow v-shadow blur-radius color;
h-shadow
v-shadow
blur-radius
color
The position of the horizontal shadow
The position of the vertical shadow
Optional. The blur radius. Default value is 0
Optional. The color of the shadow
The line-height property specifies the line height.
The vertical-align property sets the vertical alignment of an element.
Value | Description |
---|---|
baseline | Align the baseline of the element with the baseline of the parent element. This is default |
length | Raises or lower an element by the specified length. Negative values are allowed |
% | Raises or lower an element in a percent of the "line-height" property. Negative values are allowed |
sub | Aligns the element as if it was subscript |
super | Aligns the element as if it was superscript |
top | The top of the element is aligned with the top of the tallest element on the line |
text-top | The top of the element is aligned with the top of the parent element's font |
middle | The element is placed in the middle of the parent element |
bottom | The bottom of the element is aligned with the lowest element on the line |
text-bottom | The bottom of the element is aligned with the bottom of the parent element's font |
The white-space property specifies how white-space inside an element is handled.
Value | Description |
---|---|
normal | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default |
nowrap | Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered |
pre | Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML |
pre-line | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks |
pre-wrap | Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks |
The word-spacing property increases or decreases the white space between words.
Create a web page using all the properties from this presentation
Use inline and and internal styles
Create a web page using all the properties and all the selectors from this presentation using external stylesheet