Except where otherwise noted, the contents of this presentation are © Copyright 2007 Marty Stepp and are licensed under the Creative Commons Attribution 2.5 License.
h2 { border: 5px solid red; }
border
: all properties of border on all 4 sidespx
, pt
, em
, %
, or one of the following general widths: thin
, medium
, thick
)none
,
hidden
,
dotted
,
dashed
,
double
,
groove
,
inset
,
outset
,
ridge
,
solid
border-color
, border-width
, border-style
: specific properties of border on all 4 sidesborder-bottom
,
border-left
,
border-right
,
border-top
:
all properties of border on a particular sideborder-bottom-color
,
border-bottom-style
,
border-bottom-width
,
border-left-color
,
border-left-style
,
border-left-width
,
border-right-color
,
border-right-style
,
border-right-width
,
border-top-color
,
border-top-style
,
border-top-width
:
specific properties of border on a particular sideh2 { border-left: thick dotted #CC0088; border-bottom-color: rgb(0, 128, 128); border-bottom-style: double; }
border-bottom-width
above)padding
: padding on all 4 sidespadding-bottom
: padding on bottom side onlypadding-left
: padding on left side onlypadding-right
: padding on right side onlypadding-top
: padding on top side onlyp { padding: 20px; border: 3px solid black; } h2 { padding: 0px; background-color: yellow; }
This is the first paragraph
This is the second paragraph
p { padding-left: 200px; padding-top: 30px;
background-color: fuchsia; }
This is the first paragraph
This is the second paragraph
margin
: margin on all 4 sidesmargin-bottom
: margin on bottom side onlymargin-left
: margin on left side onlymargin-right
: margin on right side onlymargin-top
: margin on top side only
p {
margin: 70px;
background-color: fuchsia;
}
This is the first paragraph
This is the second paragraph
p {
margin-left: 200px;
background-color: fuchsia;
}
This is the first paragraph
This is the second paragraph
p { width: 400px; background-color: yellow; } h2 { width: 50%; background-color: aqua; }
This paragraph uses the first style above.
width
, height
: how wide or tall to make this elementmax-width
,
max-height
,
min-width
,
min-height
: the maximum or minimum size of this element in the given dimensionauto
marginsp { width: 500px; margin-left: auto; margin-right: auto; }
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
width
is settext-align: center;
instead
float
property (reference)
img.floatright { float: right; width: 130px; }
Borat Sagdiyev (born July 30, 1972) is a fictional Kazakhstani journalist played by British-Jewish comedian Sacha Baron Cohen. He is the main character portrayed in the controversial and successful film Borat: Cultural Learnings of America for Make Benefit Glorious Nation of Kazakhstan. Borat ...
float
can be left
, right
, or none
(default)float
bug: missing widthI am not floating, no width
I am floating right, no width
I am not floating, 45% width
I am floating right, 45% width
width
property value
width
is specified, the floating element may occupy 100% of the page width, so no content can wrap around itIt was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to heaven, we were all going direct the other way - in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only.
Result: | Interaction Pane: |
---|---|
|
|
clear
property
p { background-color: fuchsia; }
h2 { clear: right; background-color: yellow; }
Homestar Runner is a Flash animated Internet cartoon. It mixes surreal humour with references to 1980s and 1990s pop culture, notably video games, classic television and popular music.
clear
can be left
, right
, both
, or none
(default)
div#sidebar { float: right; }
div#footer { clear: right; }
"Never increase, beyond what is necessary, the number of entities required to explain anything." William of Ockham (1285-1349)
At W3Schools you will find all the Web-building tutorials you need, from basic HTML and XHTML to advanced XML, XSL, Multimedia and WAP.
W3Schools - The Largest Web Developers Site On The Net!
div
elements should float
, and how?
position
property (examples)
div#rightside {
position: fixed;
right: 10%;
top: 36%;
}
absolute
or relative
positioning)top
, bottom
, left
, right
valueswidth
property as wellabsolute
elements in a relative
elementz-index
propertyz-index
winsauto
(default) or a numberobject.style.zIndex = "value";
left
, right
, top
, or bottom
value can be negative to create an element that sits outside the visible browser windowwidth
, height
, min-width
, etc.) are ignored for inline boxesmargin-top
and margin-bottom
are ignored, but margin-left
and margin-right
are nottext-align
property controls horizontal position of inline boxes within it
vertical-align
property aligns it vertically within its block box
vertical-align
propertytop
, middle
, bottom
, baseline
(default), sub
, super
, text-top
, text-bottom
, or a length value or %
baseline
means aligned with bottom of non-hanging lettersobject.style.verticalAlign = "value";
vertical-align
example<p style="background-color: yellow;"> <span style="vertical-align: top; border: 1px solid red;"> Don't be sad! Turn that frown <img src="sad.jpg" alt="sad" /> upside down! <img style="vertical-align: bottom" src="smiley.jpg" alt="smile" /> Smiling burns calories, you know. <img style="vertical-align: middle" src="puppy.jpg" alt="puppy" /> Anyway, look at this cute puppy; isn't he adorable! So cheer up, and have a nice day. The End. </span></p>
Don't be sad! Turn that frown upside down! Smiling burns calories, you know. Anyway, look at this cute puppy; isn't he adorable! So cheer up, and have a nice day. The End.
<p style="background-color: red; padding: 0px; margin: 0px"> <img src="images/smiley.png" alt="smile" /> </p>
padding
and margin
of 0vertical-align
to bottom
fixes the problem (so does setting line-height
to 0px
)display
property
h2 { display: inline; background-color: yellow; }
none
, inline
, block
, run-in
, compact
, ...visibility
property
p.secret {
visibility: hidden;
}
display
to none
insteadvisible
(default) or hidden