Week 8
CASCADING STYLE SHEETS
Add styles to HTML pages by targeting specific tags
You can also have several declarations in a single rule
How to set up an external CSS document and link to your HTML document
Using inline and embedded styles
If there's conflicting styles, the browser uses the "cascade" to determine which style to show.
You can override all styles by assigning the !important indicator to a declaration.
The more specific the tag is, the greater chance of the browser choosing to load that style
ex: em{color:green;}
p em {color: red;}
The items at the top will override items below them
If rules of identical weight conflict, which ever comes last, wins
p {color: green;}
p {color: yellow;}
p{
color: green;
color: yellow;
}
You can apply a style to more than one selector
p, em, li {color: red;}
Every element on the page is it's own "box"
You can apply properties such as margins, padding, backgrounds and borders.
You can also reposition them
font-family: Arial, Helvetica, sans-serif;
font-size: size of font (ems, px or %)
font-weight: boldness (normal, bold, or value)
font-style: italics (normal, italic, oblique, inherit)
font-variant: small caps (normal, small-caps, inherit)
font: style weight variant size/line-height family
text-color: changes the font color (name or hexdex #)
EMs are a relative measurement and is based on the parents measurement. They're good for scaling fonts are are often seen used in responsive design.
The default body size is always set to 1em
1em is about 16px;
You can convert from ems using a simple math equation
current px measurment/16px = em
12px/16px=.75em;
Always include the decimal for an exact conversion
Remember: ems are based on the inherited size of the element.
If I set an body tag to 18px (1.125em) and I wanted an H1 tag inside the article tag to be 14px, my equation would change to:
14px/18px=.77777778em
target/content=result
element selectors: p {font-size:12px}
grouped selectors: p, em, li {font-size:12px}
Contextual Selectors
Selects an element based on its context
Descendant selectors: targets an element contained within another element
p em {color:green;} Will only target em within a p
Child Selector: targets only the direct children
p >em{color:green} will only target an em tag if it's within the p with no other tags in between.
Adjacent Sibling: targets an element that comes directly after another element with the same parent
p+em{color:green} will only target an em tag if it directly comes after a </p>
CONTEXTUAL SELECTORS
General Sibling: selects an element that shares a parent and occurs after in the source order. BUT it doesn't have to be directly after
p~em:{color:green;} will target an em tag if it comes after the p (there can be tags in between)
Does not work in IE8 or lower
CONTEXTUAL SELECTORS
<p id="red">Blah Blah</p>
#red {color: red;}
ID SELECTORS (unique)
<li class="textChange">bla bla</li>
.textChange {font-size: 24px;}
CLASS SELECTORS (not unique)
The top will override what's below it
1. ID selectors
2. Class selectors
3. Contextual selectors
4. Individual element selectors
strong{color:red;}
h1 strong{color:green;}
There are several ways you can specify a color value
You can specify an opacity value of a color two different ways: