layout - What is the best way to position a div in css? -
i'm trying place menu:
<div class="left-menu" style="left: 123px; top: 355px"> <ul> <li> categories </li> <li> weapons </li> <li> armor </li> <li> manuals </li> <li> sustenance </li> <li> test </li> </ul> </div>
on left hand side of page. problem if use absolute or fixed values.
different screen sizes render navigation bar differently. have second div contains main content needs moved right, far i'm using relative values seems work no matter screen size.
float
indeed right property achieve this. however, example given bmatthews68 can improved. important thing floating boxes must specify explicit width. can rather inconvenient way css works. however, notice px
unit of measure has no place in world of html/css, @ least not specify widths.
always resort measures work different font sizes, i.e. either use em
or %
. now, if menu implemented floating body, means main content floats “around” it. if main content higher menu, might not want:
float1 http://page.mi.fu-berlin.de/krudolph/stuff/float1.png
<div style="width: 10em; float: left;">left</div> <div>right, spanning<br/> multiple lines</div>
you can correct behaviour giving main content margin-left
equal width of menu:
float2 http://page.mi.fu-berlin.de/krudolph/stuff/float2.png
<div style="width: 10em; float: left;">left</div> <div style="margin-left: 10em;">right, spanning<br/> multiple lines</div>
in cases want give main content padding-left
doesn't “stick” menu closely.
by way, it's trivial change above menu on right side instead of left: change every occurrence of word “left” “right”.
ah, 1 last thing. if menu's content higher main content, render oddly because float
odd things. in case, have clear box comes below floating body, in bmatthews68's example.
/edit: damn, html doesn't work way preview showed it. well, i've included pictures instead.
Comments
Post a Comment