Solved

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

Posted on 2007-11-21
3
1,545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 30

Expert Comment

by:VirusMinus
ID: 20332898
always try and use the strict DOCTYPE
0
 

Author Comment

by:iangregson1
ID: 20333010
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
ID: 20335706
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get chosen background-color on every line? 10 44
center text in div with CSS3 2 30
modify font on ninja form 1 23
Checkbox changes display when resizing window 8 26
When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

734 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