Cascading Style Sheets
Add styles to HTML pages by targeting specific tags
property
selector
You can also have several declarations in a single rule
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 browser will load the p em style because it's more specific
Demo
The items at the top will override items below it
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;}
Demo
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
The default body size is always set to 1em (16px)
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
Demo
Remember: ems are based on the inherited size of the element.
If I set an article 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
Demo
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
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
Contextual Selectors
target elements by their id values
<p id="red">Blah Blah</p>
#red{color:red;}
ID Selectors
Works like an id selector except you can target a class
<li class="textChange">bla bla</li>
.textChange{}
Class Selectors
Demo
1. ID selectors
2. Class selectors
3. Contextual selectors
4. Individual element selectors
strong{color:red;}
h1 strong{color:green;}
The top will override what's below it
list-style-image: allows you to add an image for a bullet (url:path to image)
Demo
There are several ways you can specify a color
You can specify an opacity value of a color two different ways:
shorthand: shorthand (can appear in any order)
background: background-color background-image background-repeat background-attachment background-position
background:url(kittens.jpg) no-repeat left top fixed #444444;
Demo
You can also call multiple background images. The image called first will be placed in front.
background-image: url(kittens.jpg), url(dogs.jpg);
background-position: left top, center top;
background-repeat: no-repeat, repeat-y;
You can also use the short hand version to call multiple background images:
background: url(kittens.jpg) left top no-repeat, url (dogs.jpg) left center, repeat-y;
are applied to already existing classes
Demo
are applied to already existing classes
p:before{
content:"Once upon a time";
font-weight:bold;
color:purple;
}
are applied to already existing classes
img[title]{border3px solid #555;}
element [attribute="exact value"]
CSS: input[type="text"]{border:1px solid #444;}
are applied to already existing classes
CSS Gradient Tools
CSS gradients are very complex. Using a tool can help simplify the process
Use the property border-radius:
.square{
border-radius: 25px;
border: 2px solid #73AD21;
}
Below sets all 4 corners to a radius of 25px;
.square{
border-top-left-radius: 15px;
border-top-right-radius: 20px;
border-bottom-right-radius: 25px;
border-bottom-left-radius: 30px;
border: 2px solid #73AD21;
}
You can also affect all 4 corners independently
Use the property box-shadow adds a drop shadow to an elements frame
box-shadow: offset-x offset-y blur color;
.square{
border-radius: 25px;
box-shadow: 5px 5px 2px #444;
}
You can also add additional values:
box-shadow: offset-x offset-y blur spread color;
.square{
border-radius: 25px;
box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2);
}
You can also use numerous web tools to help generate a box shadow
You can also add drop shadows to text
text-shadow: offset-x offset-y blur color
h1{
text-shadow: 1px 1px 2px black;
}
Text Shadow Tools