我需要哪种文档类型?
我在使用默认 VS 文档类型时遇到问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
在我的页面上我有一个内容框,其中包含两个 div,一个向左浮动,另一个向右浮动。右侧浮动 div 包含高度:100%,但是,这永远不会应用于匹配左侧 div 的高度。
当我在 IE8 中删除 doctype(不好,我知道,但只是测试......)时,该网站看起来就像狗的早餐,而在 Chrome 和 Firefox 中,它看起来完全符合我的要求。
I'm having an issue using the default VS doctype of
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
On my page I have a content box, which contains two divs, one floated left and the other floated right. The right floated div contains a height: 100%, however, this is never applied to match the height of the left div.
When I remove the doctype (bad, I know, but was just testing..) in IE8 the site looks like a dogs breakfast, whereas in Chrome and Firefox it looked exactly as I wanted it to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该使用适合您所编码的 HTML 版本的任何文档类型。例如 HTML 5 的
。
You should use whatever doctype fits the version of HTML you have been coding for. e.g
<!DOCTYPE HTML>
for HTML 5.没有 DOCTYPE 基本上意味着浏览器将假定 HTML 损坏并尝试猜测,因此您永远无法获得连贯的结果。只需选择您选择的任何规范(我尽量避免使用 XHTML,但这只是个人喜好问题)并通过 HTML 验证器运行您的代码,直到没有错误为止。
No DOCTYPE basically means that browsers will assume broken HTML and will try to guess so you'll never get coherent results. Just pick any spec of your choice (I try to avoid XHTML but it's a matter of taste) and run your code through an HTML validator until it has no errors.
您应该使用这样的 Doctype:
你的 Doctype 会触发标准模式,所以你只需要弄清楚为什么浏览器没有按照你的预期呈现内容(这很可能是由于你的 CSS 或标记中的错误)可以使用 validator 检测到。
You should use a Doctype that:
The Doctype you have triggers standards mode, so you just need to figure out why browsers don't render content as you expect (there is a high chance that this will be due to errors in your CSS or markup that could be detected with a validator).
不是答案:搜索两列布局。
提示:搜索“clear:both”风格的解决方案。 (请参阅http://www.quirksmode.org/css/clearing.html)
Not an answer: Search for two column layout.
Hint: search for "clear: both"-style solutions. (see http://www.quirksmode.org/css/clearing.html)
您是否正在寻找高度相同的两个 div?在标准模式下永远不会出现这种情况,因为 div 的行为方式与表格单元格的行为方式不同。表格单元格会拉伸以满足表格的尺寸,div 是独立的容器,并且行为方式不同。
然而,有一些解决方案,例如假柱技术。
这是一篇关于“假列”技术的文章。
Are you looking for the two divs to be identical in height? That will never be the case in standards mode because divs don't behave in the same way that table cells do. Table cells stretch to meet the dimensions of the table, divs are independent containers and do not behave in the same manner.
However there are solutions such as the Faux Column technique.
Here's a an article on the "Faux Columns" technique.