"身高= 100%"在使用<!DOCTYPE>时不能在html中工作? [英] "Height=100%" is not working in html when using <!DOCTYPE>?

查看:59
本文介绍了"身高= 100%"在使用<!DOCTYPE>时不能在html中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用没有 DOCTYPE 的HTML时,我的HTML页面 Height = 100%正在工作。



但是,当我使用 DOCTYPE 时,高度工作不正常......

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/的xhtml1-transitional.dtd> 
< html xmlns =http://www.w3.org/1999/xhtmllang =en>
< head>

< meta http-equiv =Content-Typecontent =text / html; charset = windows-1252>
< title>新页面1< / title>
< / head>

< body>

< table cellpadding =0cellspacing =0width =11height =100%>
< tr>
< td height =100%bgcolor =#008000>& nbsp;< / td>
< / tr>
< / table>

< / body>



如何解决这个问题?

解决方案添加 DOCTYPE 会从怪癖模式到标准模式。在标准模式下, html body 元素不会默认为视口大小的100%(浏览器窗口);相反,他们只是需要遏制自己的孩子。 表格 100%的高度表示包含元素的100%,但这只是包含表格内容的大小。怪异模式是模拟旧版浏览器的行为,其中 html body 元素填充了视口。 / p>

要解决这个问题,您只需将其添加到您的文档中:

 <风格> 
html,body {height:100%}
< / style>


When I use HTML without DOCTYPE, my HTML page Height=100% is working.

But when I use DOCTYPE, height is not working correctly...

<!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" lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<table cellpadding="0" cellspacing="0" width="11" height ="100%">
    <tr>
        <td height="100%" bgcolor="#008000">&nbsp;</td>
    </tr>
</table>

</body>

How to solve this problem?

解决方案

Adding a DOCTYPE switches you from quirks mode to standards mode. In standards mode, the html and body elements do not default to 100% of the size of the viewport (browser window); instead, they are only as large as they need to be to contain their children. The table height of 100% means 100% of the containing element, but that's only as large as it needs to be to contain the contents of the table. Quirks mode is an emulation of the behavior of older browsers, in which the html and body elements filled the viewport.

To fix the problem, you just need to add this to your document:

<style>
  html, body { height: 100% }
</style>

这篇关于&QUOT;身高= 100%&QUOT;在使用&lt;!DOCTYPE&gt;时不能在html中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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