- From: Hakon Lie <howcome@w3.org>
- Date: Thu, 14 Aug 1997 12:13:01 +0200 (MET DST)
- To: Liam Quinn <liam@htmlhelp.com>
- Cc: www-html@w3.org
Liam Quinn writes:
> >Speaking of which, how do you align an image (and its
> >resulting ALT text)? Currently, I just let it float left, but I would
> >really prefer a centered graphic.
>
> Use { text-align: center } with the block-level element containing the
> image. E.g.,
>
> P.footer { text-align: center }
> ...
> <P CLASS=footer><IMG SRC=foo.gif ALT="Some centred stuff"></P>
Yup, the 'text-align' property centers the content of an element which
(despite its name) can also be an image.
If you want to center the element itself -- not its content -- you can
do something a la:
IMG { display: block; margin-left: auto; margin-right: auto }
This is described in section 4.1.2 of CSS1 [1]:
.. if both 'margin-left' and 'margin-right' are 'auto', they will be
set to equal values. This will center the element inside its parent.
A test page can be found from [2].
[1] http://www.w3.org/TR/REC-CSS1#horizontal-formatting
[2] http://www.w3.org/Style/CSS/Test/edge
-h&kon
H å k o n W i u m L i e
howcome@w3.org http://www.w3.org/people/howcome
World W i d e Web Consortium
Received on Thursday, 14 August 1997 06:13:05 UTC