Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

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

1 solution

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/]
 
Share this answer
 
Comments
KFLee 18-Nov-10 8:43am    
Thanks, I read (good articles) and tested following the suggestion of the article. It works with:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

Thus it seems that the conclusion is CSS will behave better with xhtml11. For Dreamweavere 8 user noted that it will put xhtml1.dtd when create new file; so you need to change it.
jim lahey 18-Nov-10 10:13am    
glad to be of help. any rating for the answer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900