HTML标头导致CSS边距故障 [英] The HTML header causes CSS margin malfunction

查看:96
本文介绍了HTML标头导致CSS边距故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我得到了一个简短的代码,如下所示:如果包含第一个doctype行,css边距(在#StripLeft和#StripRight中)将停止工作吗?我可以通过删除该行使其工作,但是为什么呢?请给我任何解释.

Hi,

I got a short code as follow: the css margin (in #StripLeft and #StripRight) would stop working if the first doctype line is included? I can make it work by remove the line but why? Any explanation please.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<style type="text/css" media="all">

div {
float:left;
overflow:auto;
}

#WholePage {
width:680px;   border:groove; margin:0 0 0 0; text-align:center; overflow:scroll; background: #FFFFCC; vertical-align:top;
}

#PageStrip {
width:100%; height:20%; border:groove; margin:0 0 0 0; text-align:center; background: #33FFCC; vertical-align:top;
}

#PageStrip #StripLeft {
width:30%; border:groove; margin:10 10 10 10; text-align:center; background-color:#999999; vertical-align:top;
}

#PageStrip #StripRight {
width:30%; border:groove; margin:10 10 10 10; text-align:center; background-color:#FFCCCC; vertical-align:top; }
</style>


<body>
<div id="WholePage">
<div id="PageStrip">
    <div id="StripLeft">
        <span id="Box1">xxxx</span>
        </div>
    <div id="StripRight">
        <span id="Box2">yyyy</span>
        </div>
    </div>

<div id="PageStrip">
    no division in this strip
    </div>

<div id="PageStrip">
    <div id="StripLeft">
        <span id="Box3">zzzz</span>
        </div>
    <div id="StripRight">
        <span id="Box4">wwww</span>
        </div>
    </div>

</div>

</body>
</html>

推荐答案

您的doctype声明将对您的页面以及该页面上的CSS产生影响.它的解释远比我在这里能做的要好:

[ http://www.alistapart.com/articles/doctype/]
your doctype declaration will have an effect on your page and the css on that page. its explained far better than I will ever be able to here:

[http://www.alistapart.com/articles/doctype/]


这篇关于HTML标头导致CSS边距故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆