php - DOCTYPE 打破了第 n 个 child 的背景颜色

标签 php html css doctype

我的 CSS 已通过验证,但在添加 <!DOCTYPE html> 时仍然中断.我究竟做错了什么?我搜索了论坛,常见的回应似乎是 [add height: 100% to the body, html tags.做到了,但没有运气。

没有 DOCTYPE:http://www.babeweiser.com/rockhistory/ 使用 DOCTYPE:http://www.babeweiser.com/rockhistory/test.php

CSS

html, body 
{
height: 100%;
width: 100%;
background: #333333; 
}
div.Container
{
margin: auto;
width: 90%;
background: #5e6d3d;
padding: 10px;
}
p 
{
font-family: sans-serif;
}
.Table
{
    display: Table;
}
.Title
{
    display: table-caption;
    text-align: center;
    font-weight: bold;
    font-size: larger;
    background: #c6d4a8;
}
.Heading
{
    display: table-row;
    font-weight: bold;
    text-align: center;
}
.Row
{
    display: table-row;
    height: 100%; width: 100%;
}
div.row:nth-child(odd)
{
background: #daedb2;
}
div.row:nth-child(even)
{
background: #c6d4a8;
}
.Cell
{
    display: table-cell;
    padding: 15px;
}
select:required:invalid 
{
color: #999;
}
option {
color: #000;
}

测试.php:

<!DOCTYPE html>
<html>
<head>
<title>Today in Rock History</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
<link rel="stylesheet" type="text/css" href="rockhistory2.css">

<script>
$(function() {
  $.ajax({  
      type: "POST",  
      url: "pull_history2.php",  
      data: "" + status,  
      success: function(data){  
          document.getElementById("demo").innerHTML = data;

      }  
  });
});
</script>

<script>
$(document).ready(function()
{   
    $(document).on('submit', '#reg-form', function()
    {

        var data = $(this).serialize();

        $.ajax({

        type : 'POST',
        url  : 'pull_history2.php',
        data : data,
        success :  function(data)
                {       
                document.getElementById("demo").innerHTML = data;
                }
        });
        return false;
    });
});

</script>



</head>

<body>

<div class="Container">
<form id="reg-form" name="reg-form" method="post">
<select name="month" required  id="month" size="1">
<option value="" disabled selected>Month</option>
<?php 
$mo = 1; 
while($mo <= 12) {
    echo '<option value= "' . $mo . '">' . date("F", mktime(0, 0, 0, $mo+1, 0, 0)) . '</option>';
    echo "\n";
    $mo++;
} 
?>
</select>
<select name="day" required id="day" size="1">
<option value="" disabled selected>Day</option>
<?php
$da = 1; 
while($da <= 31) {
    echo '<option value= "' . $da . '">' . date("j", mktime(0, 0, 0, 0, $da, 0)) . '</option>';
    echo "\n";
    $da++;
} 
?>

 </select>
 <button type="submit" >Go</button>

 </form>

    <p id="demo"></p>

</div>

</body>

</html>

pull_history2.php:

<?php

if($_POST) {
    $month= $_POST['month'];
    $day= $_POST['day'];
} else {
    $month = date('n');
    $day = date('j');
}

$tdate=date("F j", mktime(0, 0, 0, $month, $day, 0));

?>
<div class="Table">
    <div class="Title">
        <p><? echo "This Day in Rock History for $tdate" ?></p>
    </div>
    <div class-"heading"> 
    </div>

<?php
    $db = mysql_connect("localhost","xxx", "xxx");
    mysql_select_db("babewe5_wlup",$db);
    $result = mysql_query("SELECT * FROM RockHistory081512 WHERE      month=$month AND day=$day ORDER BY year",$db);
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
            while ($row = mysql_fetch_array ($result)) {
            ?>

            <div class="Row">
                    <div class="Cell">
                            <p><? echo $row["year"] ?></p>
                    </div>
                    <div class="Cell">
                            <p><? echo $row["history"] ?></p>                       
                    </div>
            </div>
            <?
            }
            mysql_free_result ($result);
            ?>

<div class="Row">
     <div class="Cell">
     </div>
     <div class="Cell">
           <p><small>Copyright &copy; <? echo date("Y"); ?> Tim Spencer</p>
     </div>
</div>

最佳答案

您正在 CSS 中使用 .Row.row。一个是初始上限,另一个不是。将 div.row:nth-child 更改为 div.Row:nth-child

应用 doctype 会在您的文档上强制执行一组规则。如果没有 doctype,两者将被视为相同。

关于php - DOCTYPE 打破了第 n 个 child 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33397540/

相关文章:

html - 将文本固定到页脚

html - 在固定高度/可变宽度容器内居中可变宽度/高度图像

php - 匿名函数的 use() 语句

javascript - 登录后页面刷新?

html - CSS 高度 : 100% not working on inline-block element although parent div has height

html - 表头位置 :sticky and border issue

php - 如何获取 PHP 脚本以在 li 元素中生成 javascript

php - 禁止 Internet Explorer 6.0 浏览器打开网站?

javascript - 在 Phonegap 或 Cordova 中发送多条短信

c# - asp.net 以编程方式创建表和 css 优先级