Div работает в Internet Explorer, но не в Chrome - PullRequest
1 голос
/ 30 января 2011

Похоже, мой стиль в 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;
}

Какой вариант стиля может вызывать несоответствия?

EDIT:

Источник страницы:

<!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>

Ответы [ 3 ]

5 голосов
/ 30 января 2011

Ваша страница отображается в режиме Причуды в IE8:

Quirks mode - режим рендеринга, используемый некоторыми веб-браузерами ради поддержание обратной совместимости с веб-страницами, предназначенными для пожилых браузеры или кодированные без стандартов соответствие.

Вы не можете надеяться, что страница, созданная для работы в режиме IE Quirks, будет работать в любом другом браузере - почти всегда не будет, как в данном случае.

Итак, вы должны изменить тип документа (первая строка) на <!DOCTYPE html>, чтобы вывести его из режима Quirks и устранить оттуда (многочисленные) проблемы.

Если вам нужен дополнительный совет по , как исправить ваш HTML / CSS для работы с правильным типом документа, дайте мне знать, и я предоставлю более подробный ответ, как это сделать.


Я проверял это в 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>
3 голосов
/ 30 января 2011

Это из-за IE по умолчанию box-sizing (который не совместим с w3c, кстати, и это Chrome, который работает правильно), когда он находится в режиме Quirks.

Попробуйте это:

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

В IE ширина элемента составляет 170px, в Chrome: 170px + 15px padding.

Но что вам ДЕЙСТВИТЕЛЬНО следует сделать, это использовать правильный тип документа.

0 голосов
/ 30 января 2011

его проблема вызвана различной реализацией блочной модели между ie и chrome / firefox / opera (w3c), которые ie9 теперь уже соответствуют стандарту.Я тестировал с IE8 и хромом.простое исправление:

#copyrightwrapper {
    width: 680px;
    height: 57px;
    padding-top: 25px;
    background-color: #183F61;
    font-size: 12px;
    color: white;
    clear: both; /*add this to make sure footer is in the bottom as u use float before*/
 }

, затем удалите ненужный верхний слой из другого элемента div с плавающей точкой

...