Solved

Centering image in a DIV with IE6? (got it working in FF and IE7)

Posted on 2007-11-21
3
1,540 Views
Last Modified: 2008-02-01
Hi there,

I have a image centered in a div using FF and IE7 using the following method.

.tagName { height: 200px; float: left; width: 100px; line-height: 200px; text-align:center;}
.tagContent1 {height: 200px; float: left; line-height: 200px; text-align:center; vertical-align: middle;}

        <div class="tagContent1">
            <a class="no-border" href="http//test.com">
                <img style="vertical-align:middle;" alt="test alt" src="http://www.test.com/Services/Images/gen.ashx?url=http://test.com/" />
            </a>
        </div>

this works great in FF and IE7, ie 6 isn't aligned correctly...

Then i read a document that said to make IE6 play nice you add a font-size the same size as height.. i.e. so i got this line now

.tagContent1 {height: 200px; float: left; line-height: 200px; text-align:center; vertical-align: middle; font-size: 200px; }

But this throws everything off inc ie7 and ff

my img which is inside the div as the following on it

<img style="vertical-align: middle;"  for testing..

It may have something to do with the doctype but i am using the following
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I know this is a real pain to do, as i see many others asking similar questions but i don't see a solution as yet...

Any advise really appreciated

thanks



0
Comment
Question by:iangregson1
3 Comments
 
LVL 30

Expert Comment

by:VirusMinus
Comment Utility
always try and use the strict DOCTYPE
0
 

Author Comment

by:iangregson1
Comment Utility
1.0 or 1.1, what is the difference?

but some of the css requires workarounds/hacks and using a strict doctype would prevent that no?
0
 
LVL 1

Accepted Solution

by:
edenmachine earned 500 total points
Comment Utility
It appears that the image is actually centered inside the div.  The problem seems to be that the div doesn't have a specified width therefor it "snaps" tightly around the image with no room for the image to move left or right.  If you want to fix this, simply put a width of "100%" (or whatever your need is) and then the image should center within the div's specified width.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now