CSS Flashcards
CSS stands for…
Cascading Style Sheets
It is a language for describing the presentation of web pages.
inline CSS definition
< style=”background-color: tomato” > My text < /p >
internal CSS definition
< style > p { background-color: tomato < /style >
All paragraphs are now tomatoes!
External CSS definition
One or more CSS files included in the html:
in the head tags:
< link rel=”stylesheet” type=”text/css” href=”style.css” >
CSS rule set syntax
selector { property: value; ... ... }
CSS selectors
by element(tag) p {...} by class .thisClass{...} by id #thisID{...}
CSS length units
Pixel (px): absolute size, different on different monitors, bad for accessibility
EM, %, and rem are relative sizes: 1em = as large ad your base font size.
CSS cascade…order of importance
Low to high: User agent User Author Author !important User !important
CSS cascade…specificity
The more specific declaration “wins”
low to high: element(tag) selectors class selector id selectors inline style
CSS combinators
el1, el2 {...} selector list el1 > el2 {...} el2 is a direct child of el1 el1 el2 {...} el2 is a descendant of el1 el1 + el2{...} el1 is the direct sibling of el2 el1 ~ el2{...} el1 and el2 are general siblings
CSS attribute selectors
selector[html_attribute=”value”]{…}
CSS Pseudo classes
selector:pseudo-class
fx:
a:visited{…};
CSS Pseudo Elements
selector::pseudo-element
fx:
::first-line{…}
CSS the box model
When html is rendered, a box is drawn around each element. Additionally there are optional areas:
padding, border, margin
Padding vs Margin
Padding adds space within the element
Margin adds space around an element
Block element vs inline element
Block element starts a new line and takes as much width as possible
Inline elements start from the current pos and take as mutch space as needed
Display style
Display:
block;
inline;
none;
Float
float: left;
Allows inline elements to “float” around this element
Position
position: relative; top: 20px; left: 20px;
As in the normal flow but with relative offset
Flexbox
Makes positioning easier.
Gives containers a number of properties
Responsive web design… boil it down
RWD make websites adapt to the devices they’re being viewed on instead of sending visitors to different sites.
Responsive Web Design… What does it tackle?
Different screen sizes
Different resources(computing power etc)
Different input methods
Responsive Web Design… how?
Relative length units
Flexbox
CSS media Queries
CSS media Queries
Allow you to define CSS depending on medium:
Screen size Device Resolution Input Orientation etc...
example @media screen and (max-width: 400px) { #myUnimportantDiv { display: none} }
This makes element with id myUnimportantDiv invisible when the screen is less than or equal to 400px