【问题标题】:Doctype and CSS positioning [duplicate]Doctype和CSS定位[重复]
【发布时间】:2013-09-08 01:37:05
【问题描述】:

我对 doctype 声明有一个奇怪的问题。我希望我的页脚粘在页面底部。当我声明文档类型时,它没有发生。当我删除文档类型时,页脚粘在底部。

代码 -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="styles.css"/>
</head>   
<body>  
<div id="wrapper">
    <div id="header">

    </div>
    <div id="content">

    </div>
    <div id="footer">

    </div>

</div>  
</body>
</html>

CSS -

#wrapper{
border: 1px solid black;
position: relative;
min-height:100%;
}

#header{
height: 100px; 
background: green;              
}

#content{
height: 100px; 
background: red; 
width: 400px;
margin:0 auto;      
}

#footer{
height: 50px; 
background: blue;
position: absolute; 
bottom: 0;
left:0;
right:0;
}

知道如何解决这个问题吗?

【问题讨论】:

标签: html css


【解决方案1】:

XHTML 过渡 DOCTYPE 不会在 Web 浏览器中触发 怪癖模式,但您忘记添加 XHTML 命名空间,即http://www.w3.org/1999/xhtml。通过这样做,浏览器会解释您的文档,就好像它是用旧标记编写的一样。非验证用户代理中的命名空间是识别元素并为其分配默认样式的唯一方法。如果您创建一个 XML 文档并将 XHTML 名称空间与 XHTML 元素与自定义元素混合使用,您将看到只有属于给定 XHTML 名称空间的元素才能从默认浏览器的样式表中获取其默认样式。

【讨论】:

  • 当文档作为text/html服务时,声明命名空间无效
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-13
  • 2012-11-18
  • 2021-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多