There are a ton of HTML elements that we can use.
Check out the list of valid HTML5 elements on MDN
Whew! How do we know which element we should use for a mark-up? How do we choose? (easy for headers, images links, etc… but other content?) →
Use the one that describes / represents the content best.
We use Cascading Style Sheets to style our pages.
Name the parts of this code: →
h3 {
font-size: 2em;
color: #ff0000;
}
this whole thing is a rule...
selector
| property value
| | |
h3 {
font-size: 2em; ---+
|---- declaration block
color: #ff0000; ---+
|_____________|
|
declaration
}
Just to get some terminology straight. When talking about CSS. →
color:red;
;
's)Do you see any difference in how elements are laid out, even if we haven't explicitly applied styles? →
Take for example… a paragraph (a p
tag) and an anchor (a link, and a
tag)
In CSS, the display
property determines how elements are laid out.
block
or inline
, but there are actually 4 possible values:
block
inline
none
inline-block
(Well, and a bunch of others)
block-level elements - start on a new line and stretch out horizontally as far as they can; have a height and width
What are some common block-level elements? →
div
- standard and generic block level element (again, doesn't inherently represent any type of content)p
- paragraphh1
- headerinline elements - stay on the same line (do not start a new line); do not have height and width
What are some common inline elements? →
span
- standard and generic inline elementa
- anchor (link)em
- emphasisAn element with a display value of none:
What are some common elements that are not displayed? →
script
style
title
Wait, what? An inline-block element is an element that has a width and height (a box), but flows with surrounding content inline (no new line).
On our sample page, try making the div with id="content" inline… and none: →
#content {
display: inline;
}
#content {
display: none;
}
max-width
if you don't want scrollbars when you resize to small window or have smaller resolution device
Let's try it out on our sample page… →
#content {
border: 1px solid #000;
max-width: 500px;
margin:auto;
}
As mentioned above, there's another CSS property that can hide and show elements.
visibility - can hide an element but leave space where it should have appeared
Let's see what this looks like on our sample page.
#content {
visibility: none;
}
After display, the next most important property for layout is position.
An element's position can be:
We'll take a look at the first two…
static is the default position value
position: static
is also called (no surprise here) not positionedAn element with a position of relative can be positioned relative to where it normally would be placed.
It can take these addtional properties to position it relative to what its normal position would be:
Let's try using position relative on our sample page →
#content {
border:1px solid #000;
position: relative;
top: 50px;
}
It turns out you can access CSS properties through JavaScript!
Use the style property on an element to access each individual CSS property as a property on styles. (Whew… that was a jumble… easier to show than tell!)
Doing the same as the previous slide (but making the display relative in CSS first). →
var c = document.getElementById('content')
c.style.display = 'relative';
c.style.top = '150px';