Except where otherwise noted, the contents of this presentation are © Copyright 2008 Marty Stepp and Jessica Miller and are licensed under the Creative Commons Attribution 2.5 License.
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
elementleft
, right
, top
, or bottom
value can be negative to create an element that sits outside the visible browser windowWhen trying to correctly position and lay out an element, use the following order:
text-align
vertical-align
positioning
the element
width
, 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 lettersvertical-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
)z-index
propertyz-index
winsauto
(default) or a numberobject.style.zIndex = "value";
display
propertyh2 { display: inline; background-color: yellow; }
none
, inline
, block
, run-in
, compact
, ...<ul id="topmenu"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul>
#topmenu li { display: inline; border: 2px solid gray; margin-right: 1em; }
visibility
propertyp.secret { visibility: hidden; }
display
to none
insteadvisible
(default) or hidden