margin (sometimes called "gutter")
|
margin, padding
Up Right Down Left
linky-dinkys
Link Visited Hover Active
background
Color Url Attachment H-pos V-pos Repeat
Attachment: fixed, scroll
H Position: left, center, right (or px, %)
V Position: top, center, bottom (or px, %)
Repeat: repeat(default), no-repeat, repeat-x, repeat-y
colors
RR
GG
BB
On this page:
CSS code is slate red
HTML code is slate blue
Links to two excellent CSS and
Javascript/Jquery reference
books are at the bottom of the
page.
Here are some samples of margin and padding. For each set: |
||
This shows a "div" with no margin or padding.The div is thus flush with its containing area.
Also, the contents of the div are flush with its edges. |
This shows a "div" with 8 pixel margin. The div now has an 8 pixel separation from its containing area,
but the div's contents are flush with its edges. |
This shows a "div" with 8 pixel margin and padding. The div has the 8 pixel separation from its
containing area, and its contents are inset by 8 pixels. |
This is the div's contents. Here's another line. And here's another line. And one more line. And we finish with yet another line. |
This is the div's contents. Here's another line. And here's another line. And one more line. And we finish with yet another line. |
This is the div's contents. Here's another line. And here's another line. And one more line. And we finish with yet another line. |
This shows how you can use the "U R D L argument order" shown above to position an item
uniquely within its containing area. In this example, 25 pixels from top ("U"), 20 from the left ("L"). ("R" and "D" values not used in this case.)
|
Padding has the same argument order. Here we are offsetting the div's contents 10 pixels from the top
and 5 from the left. NOTE: you can also apply margin to the "paragraph" inside the div to do the same thing. (p.xxx {margin:10px 0 0 5px;}) |
This shows a "div" with 8 pixel margin with "auto" L and R. This is used to center an element
horizontally. The "0" for "D" is ignored. Note that "auto" won't work if you have "text-align:justify" for the paragraph.
Note also that "auto" does NOT work for U and D. To center an element vertically (sometimes),
use "display:table-cell" along with "vertical-align:middle". |
This is the div's contents. |
This is the div's contents. |
This is the |
You have probably had many experiences where you added some sort of positioning tweaks to containers
or other elements and then hit "refresh", and then watched your elements move the other direction, or perhaps to see
other objects move. The above six examples might reveal, at least partially, why this is.
Judging from what is seen here, it would appear that browsers want to line up text going from left to right. Notice how the
first line of the paragraph ("This is the div's contents") is lined up as you go from left to right. And in order to line up the text,
sometimes the browser will apparently move the container instead!! This is normally not noticable, since there is usually
not a border around containers like divs or table cells, but is revealed in the samples due to the light border that was added.
The first set of three "margin and padding samples" above have been copied right below this text, but the containing divs
have been styled as "table-cell", rather than be allowed to free float as in the above samples. This forces the div containers to be lined up.
BUT, since the browser wants to align the top line of each paragraph, it has no choice but to ignore the assigned margin and padding
in order to do this. Thus the tops of all the divs are lined up with the top of the rightmost one, and the bottoms of all the divs are lined
aligned with the bottom of the leftmost div. (Had this been a "table", the table cells - "td" - would do the same thing.)
This is the div's contents. Here's another line. And here's another line. And one more line. And we finish with yet another line.
This is the div's contents. And this is another line of text.
This is the div's contents. And this is another line of text.
Paragraph
Link
Text-align left center right {text-align: |
Text-decoration overline underline line-through {text-decoration: |
Text-transform Line with capitalize Line with uppercase {text-transform: |
This is a paragraph |
This is a paragraph {line-height:90%;} |
This is a paragraph {line-height:200%;} |
Text-indent This is a paragraph with text indent of 1em (This is "body-text indent" in Word) This is a paragraph with text intent of -1em (This is called "hanging" in Word) {text-indent:1em;} |
Letter, word spacing This is a paragraph with letter-spacing 5px This is a paragraph with word-spacing 10px {letter-spacing:5px;} |
":first-letter/:first-line" pseudo elements The first letter has emphasis. First line emphasis {p.xxx:first-letter {color:red; font-size:xx-large;} |
List-style-type
|
List-style-position "inside"
|
List-style-position "outside" (default)
|
Solid |
Double |
Groove |
Inset |
Outset |
Ridge |
Dashed |
Dotted |
Double |
Groove |
Ridge |
Links display "inline" Use "display:block" to stack vertically
"hover,active"are signified by a color change and "font-style:oblique" Link 1 Link 2 Link 3 Link 4 |
"hover,active"are signified by a color change, "text-decoration:underline", and "background-color: transparent" Link 1 Link 2 Link 3 Link 4 |
"hover,active"are signified by a color change, "border-bottom:3px", and "background-color: transparent" Link 1 Link 2 Link 3 Link 4 |
display:block |
Fancy Link
a.a_sampl:link {display:inline-block;color:#443300; |
"hover,active"are signified by a color change, "border: 1px", and "background-color: transparent" Link 1 Link 2 Link 3 Link 4 |
"hover" signified by a color change, "border: outset". "active,visited" signified by a color change, "border:inset". Link 1 Link 2 Link 3 |
BG color hover: background (url) |
General syntax for forms:
<form name="NNN" method="post" action=""/>
<input type="button" value="Click here" onclick="XXX( )"/>
</form>