Div在Internet Explorer中工作但不在Chrome中

Jus*_*yer 1 html css doctype internet-explorer google-chrome

看起来我在谷歌浏览器中的样式并不像我想要的那样(链接).它在Internet Explorer 8上运行正常.

这是样式表:

@charset "utf-8";
/* Stylesheet for Northview Game Tickets */

#mainwrapper {
    width:18cm;
    height:25cm;
    background-color:#0F0;
}

#title {
    width:680px;
    height:117px;
    /*background-image:url(http://nhswag.com/tickets/images/title.png);*/
    background-color:#183f61;
}

#title-img {
    width:680px;
    height:117px;
}

#sportimage {
    width:680px;
    height:302px;
    background-image:url(http://nhswag.com/tickets/images/sportimg.png);
}

#instructionstitle {
    width:340px;
    height:57px;
    float:left;
    padding-top:15px;
    /*background-color:#353435;*/
    background-color:#183f61;
    vertical-align:text-bottom;
    color:#FFFFFF;
}

#instructions {
    width:340px;
    height:416px;
    float:left;
    text-align:left;
    padding-top:15px;
    /*background-color:#8B8B8B;*/
    /*background-color:#003;*/
    background-color:#F2EEEA;
}

#ticketinfo {
    width:170px;
    height:189px;
    float:right;
    text-align:left;
    padding-top: 15px;
    padding-left: 15px;
    /*background-color:#767676;*//*#633;*/
    background-color:#d9d5d2;
}

#barcodewrapper {
    width:170px;
    height:189px;
    float:right;
    padding-top:44px;
    /*background-color:#767676;*//*#FFF;*/
    background-color:#d9d5d2;
}

#barcode {
    border-width:thick;
    border-color:#000;
}

#adspace {
    width:340px;
    height:284px;
    float:right;
    padding-top:10px;
    background-image:url(http://nhswag.com/tickets/images/ad.png);
}

#copyrightwrapper {
    width:680px;
    height:57px;
    padding-top:25px;
    background-color:#183f61;
    font-size:12px;
    color:#FFFFFF;
}
Run Code Online (Sandbox Code Playgroud)

什么样式选项可能导致不一致?

编辑:

页面来源:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="ticketstyle.css" />
<title>NHSWAG Game Ticket</title>
</head>

<?php
    /*
    Required Fields:
    1) name
    2) type (adult/student/child)
    3) price
    4) barcodeid

    ex: http://nhswag.com/tickets/ticketprint.php?name=John%20Smith&type=Adult&price=4.98&barcodeid=9780618503049
    */

    function google_qr($url,$size ='150',$EC_level='L',$margin='0') {
        $url = urlencode($url); 
        echo '<img id="barcode" src="http://chart.apis.google.com/chart?chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$url.'" alt="QR code" width="'.$size.'" height="'.$size.'"/>';
    }
?>

<body style="background-color:#b0b0b0">
<center>
<div id="mainwrapper">

    <div id="title">
    </div>


    <div id="sportimage">
        sportimage
    </div>


    <div id="instructionstitle">
    Instructions</div>


    <div id="ticketinfo">
        <strong>Ticket Details:</strong><br><br>
        Name:<br>
        &nbsp;&nbsp;&nbsp;<?php echo $_GET["name"]; ?><br>
        Type:<br>
        &nbsp;&nbsp;&nbsp;<?php echo $_GET["type"]; ?><br>
        Price:<br>
        &nbsp;&nbsp;&nbsp;$<?php echo $_GET["price"]; ?>
    </div>


    <div id="barcodewrapper">
        <center>
            <div id="barcode">
              <?php google_qr('http://www.nhswag.com/tickets/check/ticketcheck.php?barcodeid='.$_GET["barcodeid"],100); ?>
              <?php // echo md5("JustianMeyerNorthview Gwinett Football"); ?>
            </div>
        </center>
    </div>


    <div id="instructions">
        <ol>
            <li>Print this ticket and keep it for your records.</li>
            <li>Present this ticket at the entrance of your <strong>Northview High School</strong> sponsored event.</li>
            <li>Enjoy! Ask the ticket manager for seating.</li>
        </ol>
    </div>


    <div id="adspace">
        <p>Advertisement</p>
        <p>&nbsp;</p>
    </div>
    <div id="copyrightwrapper">
        Copyright &copy; NHSwag Team, 2011
    </div>

</div>
</center>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

thi*_*dot 5

您的页面在IE8中以Quirks模式呈现:

Quirks模式是一些Web浏览器使用的渲染模式,用于保持与为旧浏览器设计的网页的向后兼容性或在没有标准一致性的情况下编码.

你不能希望在IE Quirks模式下创建的页面可以在任何其他浏览器中运行 - 它几乎总是不会,就像这里的情况一样.

因此,您应该更改doctype(第一行)以<!DOCTYPE html>使其脱离Quirks模式并从那里修复(众多)问题.

如果您需要有关如何修复HTML/CSS以使用正确的doctype的更多建议,请告诉我,我将提供有关如何执行此操作的更全面的答案.


我在IE7/8,Firefox,Chrome中进行了测试:它始终如一地呈现.

我试图保留尽可能多的HTML/CSS; 因为我这样做,代码可能更优雅,但它的工作原理!

我在顶部添加了所有样式,以便更容易测试; 你应该把它们放在你的样式表中.

您必须在适当的时候在PHP中添加.我添加了一小段PHP来输出当前年份.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>NHSWAG Game Ticket</title>
<style type="text/css">
html, body {
    margin: 0;
    padding: 0;
    border: 0
}
body {
    background: #b0b0b0;
    padding: 5px
}

#mainwrapper {
    width: 680px;
    margin: 0 auto
}

#title {
    height: 117px;
    /*background-image:url(http://nhswag.com/tickets/images/title.png);*/
    background-color: #183f61;
}
#sportimage {
    height: 302px;
    background-image: url(http://nhswag.com/tickets/images/sportimg.png);
}

#floatContainer {
    background: #f2eeea;
    overflow: auto
}
#left {
    float: left;
    width: 50%
}
#right {
    float: right;
    width: 50%
}

#instructionstitle {
    height: 32px;
    padding-top: 12px;
    /*background-color: #353435;*/
    background-color: #183f61;
    vertical-align: text-bottom;
    color: #fff;
    text-align: center
}

#barcodewrapper {
    overflow: auto;
    background: #d9d5d2
}
#barcode {
    float: left;
    padding: 20px
}
#ticketinfo {
    float: left;
    padding: 16px 0
}
#ticketinfo dd {
    margin-left: 12px
}
#ticketinfo dl {
    margin: 0
}

#copyrightwrapper {
    height: 35px;
    padding-top: 22px;
    background-color: #183f61;
    font-size: 12px;
    color: #fff;
    text-align: center
}
#adspace {
    height: 284px;
    background: #fff;
    text-align: center;
    background:url(http://nhswag.com/tickets/images/ad.png) no-repeat
}
#adspace p {
    margin: 0;
    padding: 12px 0
}
</style>
</head>

<body>

<div id="mainwrapper">
    <div id="title">title</div>
    <div id="sportimage">sportimage</div>

    <div id="floatContainer">
        <div id="left">
            <div id="instructionstitle"> Instructions </div>
            <div id="instructions">
                <ol>
                    <li>Print this ticket and keep it for your records.</li>
                    <li>Present this ticket at the entrance of your <strong>Northview High School</strong> sponsored event.</li>
                    <li>Enjoy! Ask the ticket manager for seating.</li>
                </ol>
            </div>
        </div>

        <div id="right">
        <div id="barcodewrapper">
            <div id="barcode"> <img id="barcode" src="http://chart.apis.google.com/chart?chs=100x100&cht=qr&chld=L|0&chl=http%3A%2F%2Fwww.nhswag.com%2Ftickets%2Fcheck%2Fticketcheck.php%3Fbarcodeid%3D" alt="QR code" width="100" height="100"/> </div>
            <div id="ticketinfo"> <strong>Ticket Details:</strong><br>
                <br>
                <dl>
                    <dt>Name:</dt>
                        <dd>John Smith</dd>
                    <dt>Type:</dt>
                        <dd>Student</dd>
                    <dt>Price:</dt>
                        <dd>$5</dd>
                </dl>
                </div>
            </div>
            <div id="adspace">
                <p>Advertisement</p>
                <p>&nbsp;</p>
            </div>
        </div>
    </div>

    <div id="copyrightwrapper"> Copyright &copy; NHSwag Team, <?php echo date('Y') ?></div>
</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)