|
Posted by dorayme on May 12, 2008, 5:52 pm
Please log in for more thread options
> [...]
> > You can centre an element by stating a width and auto left and right
> > margin for it in the css. This will do the trick in most modern
> > browsers, use a strict doctype like 4.01:
> >
> > .element {
> > width: 30units;
> > margin: auto;
> > }
> >
> > and
> >
> ><div class="element">div</div>
> >
> > or
> >
> ><div class="element"><img src="..." ...></div>
> >
> > or indeed, quite often,
> >
> ><img class="element" ...>
> >
> > With an image, the "units" in px is mostly appropriate
>
> For <img class="element"> you will also need to add display: block.
> Perhaps:
>
> img.element {
> width: 30units;
> margin: auto;
> display: block;
> }
>
> Auto margins can only be used to centre block-level things. IMG is
> inline by default.
Quite right... too quick and brief of me... Thanks for this...
It could be added too that if it is just an image, "text-align: center"
on the parent div will also do the trick.
--
dorayme
|