Admin@mbox3.magellan-net.de
alina@yourmx.de
bm@schweinischer-bote.de
boris@cosmeta.de
boss@dan2n.de
btiggemann@mbox3.magellan-net.de
catcher009@blacknbeauty.de
Christopher_Zantopp@web.de
dok123@discardmail.com
dominik.keilbach@rocketmail.com
dominik2712@web.de
einkauf@dan2n.de
elke@kunesch.eu
erik_burgbacher_bi17l4lo@send.electronicmailfor.me.uk
feedme@die-bauer.de
feedme@dog-net.org
feedme@drakensang.de-web.cc
feedme@kraffner.de
feedme@schlaegel.it
feedme@sql-kunesch.de
feedme@wipeout6.de
fetcher@open-host.de
frank@spiracyworld.co.uk
getspam@schlaegel-online.de
harun-ali@web.de
iCollectGarbage@gmx.de
ifyoudone@r0ckt.de
ifyyou@r0ckt.de
info@die-bauer.de
info@mbox3.magellan-net.de
info@r0ckt.de
info@rbcms.de
john.deer@spamreducer.eu
john@cannedmeat.elementfx.com
k.tramm@xspin.de
Karl-Heinz.Becher@gmx.de
Kevin.Becaud@bio-muesli.info
kickers88@live.de
knuddels119k@yahoo.de
loremiosumsitdoloramet@yahoo.de
loremiosumsitdoloramet@yahoo.de
lotharwalter@ymail.com
luna@r0ckt.de
matz0302oyqp@domut.de
mgoessel@gmx.net
michael.k@drakensang.de-web.cc
michael.k@drakensang.de-web.cc
michael.k@sql-kunesch.de
michaknopf@googlemail.com
mk@r0ckt.de
msneijder@mbox3.magellan-net.de
nasti_mkorsa@sql-kunesch.de
newcyborg@gmx.net
schlucks@gmx.net
schwarz@die-bauer.de
service@mbox3.magellan-net.de
sp4mf4ng@j-schmitz.net
spam@teh1.de
spamcatcher@spamtrap.dtdns.net
spamela@spamschlucker.org
spamhog.ihatespam@gmail.com
spamlearn@schlarb-it.de
spamlearn@schlarb-it.de
spamtarget@junge-piraten.de
spamtrap@r0ckt.de
spamtrap@sprachdidaktik.org
spoof@dog-net.org
stephan@spamschlucker.org
support@mbox3.magellan-net.de
thanks@marvin-webservice.net
trap.mitschutz@sprachdidaktik.org
trap@sprachdidakt.de
trap@sprachdidaktik.org
trep@marvin-webservice.net
unwanted@shadowpage.de
vertrieb@dan2n.de
wb@munzinger.de
willmehr@drakensang.de-web.cc
willmehr@drakensang.de-web.cc
willmehr@wipeout6.de
wir@dragoncrew.de
xkbzy@grossermist.de
a Image

The first thing you should know about a "div", is that a div is a block-element.
That means, that a div usually takes 100% of available width.

for example:

  1.  
  2. <div>I'm a div</div>
  3.  


takes 100% of available width, as you can see here:

'Im a div


You can set your divs to a fixed width, for example:

  1.  
  2. <div style="width:250px">Im a div</div>
  3.  


This looks like:

Im a div


How to center a div element with fixed width isn't a miracle:
Simple set its left- and rightmargin to "auto":

  1.  
  2. <div style="width:250px; margin:0 auto;"></div>
  3.  


Im a div


Note:
Internet Explorer doesn't know this in some doc types. As you can see, my page uses the doc type "XHTML 1.0" - where the IE seems to understand, what he should do.

If you can't change the doc type of your website (or maybe older IE's still don't know how to handle this) you can put another div around your div, which has the "text-align:center" attribute.

  1.  
  2. <div style="text-align:center">
  3.   <div style="width:250px;">I'm a div</div>
  4. </div>
  5.  


Another Pic
IE in Quirks-Mode


I've Included this example as an screenshot, because with my doc type, IE doesn't handle this as well.

The Save Way

There is a way, to get your div centered in (as far as i know) every ৺browser:
Use a absolute position an set a negative margin:

  1.  
  2. <div style="position:absolute; width:200px; left:50%; margin-left:-100px;">I'm a div</div>
  3.  


The idea is simple: Put your div absolute on the screen, with a distance from left of half the page.
Then, if your div is f.e. 200 pixels in width, you need to set a left margin of - 100 px.

Relative Divs?

Centering a relative div is easy too: Just set up a left-margin of "half of the rest":

  1.  
  2. <div style="width:60%; margin-left:20%;">I'm a div</div>
  3.  


looks like:

I'm a div


Another Workaround

Usually there are the two situations: div is at 100% width, or you know the width.
But sometimes, you want to center a div, that is at "unknown" width.

for example: My page includes pictures within a div container, to get a border and a comment bellow.
By default i like those containers to be centered, so i used the "margin:0 auto"-version, explained above.

While including the picture, the width and height is getting recalculated by the script. If i'd like to have my pictures aligned left by default, theres a problem: While parsing the img-tag, the script doesn't know (without modification of the source) if the picture should be aligned left, centered or right.

In this case, you can use the deprecated tag "center" to get your div centered:

(for demonstration i use the div width of 100px)

  1.  
  2. <center>
  3.   <div style="width:100px;">I'm div</div>
  4. </center>
  5.  


this looks like:


I'm div



৺dog.net Development doesn't recommend the usage of deprecated tags. But i think it's worth to be mentioned

Related Tags:

Stay tuned:

r a t y y

Top 25 Tag-Cloud (last 14 days):

Comments on this post:

Not yet a comment...

Leave a Comment:

Captcha-Code:        reload
Name:
Captcha:
Comment:

Donate!

Like my stuff? Feel free to donate!
 
Modellbau Forum pspad Browser-Statistiken WhatPulse logo dog-net.org Valid XHTML 1.0 Transitional CSS ist valide!
Copyright © 2008 - 2010 | by dog.net Development | Imprint | Load in 1.166586