File Paths & The display Property

File Paths

Applies to all types of file references, including links to CSS files, image sources, and background images.

File Path What it means
pointB.css pointB.css is located in the current folder
css/pointB.css pointB.css is located in a folder called css
The css folder is located in the current folder
css/other/pointB.css pointB.css is located in a folder called other that is located in a folder called css that is located in the current folder
../pointB.css pointB.css is located in a folder one level up from the current folder
../../pointB.css pointB.css is located in a folder two levels up from the current folder

Connecting CSS to HTML

  1. External (Recommended): Within the <head /> element of an HTML file, use the following to link to a CSS file:
    
    <link rel="stylesheet" href="file-path-here.css" />
    						
  2. Inline: In the HTML file, within an element's opening tag, a style="" attribute contains CSS for that element.
  3. Embedded: In the HTML file, CSS is placed within the <head /> in a <style /> element.

Inline Elements


selector {
   display: inline;
}
				
  1. Cannot have a set width and height
  2. Allow other elements to their left and right
  3. Don't force sibling elements to move to a new line
  4. Respect left and right margins
  5. Do not respect top and bottom margins

Examples: <span />, <em />, <strong />,
<a />, <img />

CSS Box Model

The CSS Box Model

Property: width


selector {
   width: 300px;
}
				

Property: height


selector {
   height: 100px;
}
				

Centering Block Elements

Set a width on a block element, then use auto as a margin.


selector {
   width: 300px;
   margin: auto;
}
				

Block Elements


selector {
   display: block;
}
				
  1. Can have a set width and height
  2. Don't allow other elements to their left and right
  3. Force sibling elements to move to a new line
  4. Respect left and right margins
  5. Respect top and bottom margins

Examples: <div />, <section />, <p />, <h1 />, <h2 />, <h3 />, <h4 />, <h5 />, <h6 />, and almost everything else

Padding and Margin

Both padding and margin use the same syntax. Substitute 'margin' for 'padding' to apply margins instead.

One value:


selector {
   padding: all;
}
				

Two values:


selector {
   padding: topAndBottom leftAndRight;
}
				

Four values:


selector {
   padding: top right bottom left;
}
				
TRouBLe mnemonic

Can also specify padding-top, padding-right, padding-bottom, or padding-left to apply padding to individual sides.

Border


selector {
   border: thickness style color;
}
				

Can also specify border-top, border-right, border-bottom, or border-left to apply a border to individual sides.