Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

centering images with css1

0 views
Skip to first unread message

Daniel

unread,
May 12, 2004, 11:45:15 AM5/12/04
to
I need help with aligning an image in CSS1. I can't seem to center the
image without using the depreciated attribute in the image tag. I've tried
to use float, but no avail. I am using IE, if that helps. Thanks in
advance.

Little Dave

unread,
May 12, 2004, 12:21:12 PM5/12/04
to

To fix this.. you have to add text-align:center; to the parent element
of the IMG.

e.g if the image was inside a DIV

<div id="content">
<img src="fred.gif" width="200" height="100" alt="This is Fred."
id="imgFred" />
</div>

the CSS would be

div#content
{ width:400px;
text-align:center;
}

Then the image would be centered.

If this still fails, try adding this CSS.

img#imgFred
{ margin-left:auto;
margin-right:auto;
}

If you have an example page, we could help more.

Dave

--
Little Dave
http://www.daveholloway.co.uk
Everyone feel free to add me to your instant messengers:
MSN: daveho...@spamcop.net, YAHOO: daveho...@yahoo.com, ICQ: 104452444

Daniel

unread,
May 12, 2004, 12:50:55 PM5/12/04
to
Little Dave <da...@seess.co.uk> spewed forth
news:2gf17oF...@uni-berlin.de:

> Daniel wrote:
>> I need help with aligning an image in CSS1. I can't seem to center
>> the image without using the depreciated attribute in the image tag.
>> I've tried to use float, but no avail. I am using IE, if that helps.
>> Thanks in advance.
>
> To fix this.. you have to add text-align:center; to the parent element
> of the IMG.
>
> e.g if the image was inside a DIV
>
> <div id="content">
> <img src="fred.gif" width="200" height="100" alt="This is Fred."
> id="imgFred" />
> </div>
>
> the CSS would be
>
> div#content
> { width:400px;
> text-align:center;
> }
>
> Then the image would be centered.
>
> If this still fails, try adding this CSS.
>
> img#imgFred
> { margin-left:auto;
> margin-right:auto;
> }
>
> If you have an example page, we could help more.
>
> Dave
>

Thanks, it worked well. I was using the class ID and the .class in the
style tags, but they didn't work with the text-align. Why does id make the
difference???

Little Dave

unread,
May 12, 2004, 7:16:30 PM5/12/04
to
Daniel spake:

> Thanks, it worked well. I was using the class ID and the .class in the
> style tags, but they didn't work with the text-align. Why does id make the
> difference???

I haven't a clue. If you can send some sample code/upload an example
page, I should be able to tell you.
It is probably something to do with specifity.. which is a real
noodle-scratcher as there are so many things to remember.

Cankersore

unread,
May 13, 2004, 7:18:06 AM5/13/04
to
Little Dave <da...@seess.co.uk> spewed forth
news:2gfpidF...@uni-berlin.de:

> Daniel spake:
>
>> Thanks, it worked well. I was using the class ID and the .class in
>> the style tags, but they didn't work with the text-align. Why does
>> id make the difference???
>
> I haven't a clue. If you can send some sample code/upload an example
> page, I should be able to tell you.
> It is probably something to do with specifity.. which is a real
> noodle-scratcher as there are so many things to remember.
>
> Dave
>
>

The page I am using all of this on is www.contagiousrock.com

Little Dave

unread,
May 13, 2004, 7:28:09 AM5/13/04
to
Cankersore wrote:

> The page I am using all of this on is www.contagiousrock.com

Okay, I still haven't a clue.

But on a completely unrelated matter: I have a suggestion:
Add this script to your page (its very useful):

<script type="text/javascript">
function deOcities()
{ yfiOC(-1); }
window.onload=deOcities;
</script>

Regards

Daniel

unread,
May 13, 2004, 4:23:02 PM5/13/04
to
Little Dave <da...@seess.co.uk> spewed forth news:2gh4e7F2nn9fU1@uni-
berlin.de:

> Cankersore wrote:
>
>> The page I am using all of this on is www.contagiousrock.com
>
> Okay, I still haven't a clue.
>
> But on a completely unrelated matter: I have a suggestion:
> Add this script to your page (its very useful):
>
> <script type="text/javascript">
> function deOcities()
> { yfiOC(-1); }
> window.onload=deOcities;
> </script>
>
> Regards
>
> Dave
>

Sorry bout the name change on you. Two different computers, work and
personal. www.contagiousrock.com is the website I am using all of this on.
I have most of my css in a single stylesheet, but I only needed to center
the website image at the very top, and the band picture underneath it
(ghastly pic, isn't it?)

BTW, what does that script do?

Little Dave

unread,
May 13, 2004, 4:36:41 PM5/13/04
to
Daniel wrote:

> BTW, what does that script do?

Its a surprise. Don't worry, it doesn't do anything malicious. It will
remove something "adverty" from the page.

Dave

ps. yes. ghastly pic.

0 new messages