开发者

Div not centering in IE

开发者 https://www.devze.com 2023-04-01 08:39 出处:网络
I\'m sure you\'ve heard it before... a div is not centering correctly in IE even though it works perfectly in Chrome and Firefox. I\'ve already researched and tried stuff with text-align and auto marg

I'm sure you've heard it before... a div is not centering correctly in IE even though it works perfectly in Chrome and Firefox. I've already researched and tried stuff with text-align and auto margins but have come up empty. I also tried replacing the tags with another div or something else but did not have 开发者_高级运维any positive results. Any insight anyone can offer will be appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.thumbnails {
    background-color:white;
    border: solid 1px #000099;
    height:120px;
    width: 640px;
    overflow-y:scroll;
    margin-bottom:20px;
    position:relative;
    padding-top: 10px;
}

#hugeimage {
    background-color:white;
    border-top: solid 1px #000099;  
    border-left: solid 1px #000099;
    border-right: solid 1px #000099;
    height:550px;
    width: 640px;
    display:table-cell; 
    vertical-align:middle;
}

#hugeimage a,
#hugeimage img {
    margin: 0px;
    padding: 0px;
    border: 0px;
}

#imageinfo {
    background-color:white;
    border-left: solid 1px #000099;
    border-right: solid 1px #000099;
    width: 640px;
}

body {
    background-color: #99ccff;
    text-color: #000099;
}

</style>
</head>
<body>
    <h3 align="center">Ship Detail</h3>
    <center>
        <div class="filedrop">
            <div id="hugeimage">
                <a href="#" target="_blank">
                    <img src="images/spin/wait30.gif" />
                </a>
            </div>
            <div id="imageinfo"></div>
            <div class="thumbnails"></div>
        </div>
    </center>
</body>
</html>

I've removed data from the divs. This bare-bones markup still has the hugeimage and imageinfo divs left-aligned in IE but not in chrome/ff.


Remove the <center> tags and the align="center", and add a wrapper <div id="content"> around all your content. Then add this CSS style.

#content {
    width: 960px;
    margin: 0 auto;
}

Example:

<div id="content">
    <h3>Ship Detail</h3>
    <div class="filedrop">
        <div id="hugeimage">
            <a href="#" target="_blank">
                <img src="images/spin/wait30.gif" />
            </a>
        </div>
        <div id="imageinfo"></div>
        <div class="thumbnails"></div>
    </div>
</div>


Here is your solution:

See the working demo


I had the same issue while trying to center a loading modal box in IE. Removing

display: table; did the trick. Maybe this could help someone else.

0

精彩评论

暂无评论...
验证码 换一张
取 消