html - <!DOCTYPE html> 破坏了我的页面!为什么?

标签 html css

问题: 在我调整浏览器大小之前图像不会显示,或者只显示每个图像的一小部分;每次重新加载页面时,结果都是随机的。重新加载页面 10 次,我可以获得 10 个不同的结果。

调整窗口大小后,页面将完全按照应有的外观显示,即使将页面大小调整回原始大小,它也会继续工作。

在一个非常简单的网页遇到问题之后,

js fiddle here(工作正常):

http://jsfiddle.net/grDvW/5/

我发现我可以对我的页面源代码进行的一项更改是删除

<!DOCTYPE html> 

没有其他更改可以解决问题,但是删除该标签可以解决问题,100%。这是为什么??

HTML:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style/style.css">
<title>Title</title>
<meta name="keywords">
<meta name="description" content="The GameMode Hub is a Minecraft Server Network bringing together all of Minecraft's best and brightest server owners to present the gaming community with the largest collection of Minecraft Servers in the world!">
<meta name="author" content="Jonathan Todd">

</head>

<body>
<div class="wrap">
    <!-- begin wrap :: this will keep all of the stuff neat and in one place -->
    <div class="login-screen bg-dirt">
        <!-- begin login screen, background dirt :: sets up a background for the login and styles it with a dirt tile and holds all login elements -->
    </div>
    <!-- end login screen, background dirt -->
    <div class="welcome-screen">
        <!-- begin welcome screen :: this will hold the elements within the welcome screen, mainly just a title and the two moving wall pieces -->
        <div class="wall-left">
            <!-- begin wall left :: must I explain this? It opens and closes with the other wall -->
            <img src="http://www.new.gamemode.org/images/wall_left.png">
        </div>
        <!-- end wall left -->
        <div class="wall-right">
            <!-- begin wall-right :: must I explain this? It opens and closes with the other wall -->
            <img src="http://www.new.gamemode.org/images/wall_right.png">
        </div>
        <!-- end wall right -->
        <img class="welcome-logo" src="http://www.new.gamemode.org/images/logo.png">
        <img class="welcome-shadows" src="http://www.new.gamemode.org/images/shadows_fast.png">
    </div>
    <!-- end welcome screen -->
</div>
<!-- end wrap -->
</body>
</html>

CSS:

/* Style Setup */
body, div {
margin:0;
padding:0;
-webkit-perspective:6500;
}
table {
border-collapse:collapse;
border-spacing:0;
}
fieldset, img {
border:0;
}
address, caption, cite, code, dfn, th, var {
font-style:normal;
font-weight:normal;
}
caption, th {
text-align:left;
}
h1, h2, h3, h4, h5, h6 {
font-size:100%;
font-weight:normal;
}
q:before, q:after {
content:'';
}
abbr, acronym {
border:0;
}
.wrap, html {
width:100%;
margin:0px;
padding:0px;
height:100%;
overflow:hidden;
}
/* Style Start */
 .bg-dirt {
}
.login-screen {
z-index:0;
}
.welcome-screen {
z-index:1;
width:100%;
height:100%;
}
.wall-left {
position:absolute;
z-index:2;
height:100%;
left:0px;
}
.wall-right {
position:absolute;
z-index:3;
height:100%;
right:0px;
}
.welcome-logo {
position:absolute;
z-index:4;
margin-left:auto;
margin-right:auto;
}
.welcome-shadows {
position:absolute;
z-index:5;
width:100%;
}

最佳答案

我不确定为什么会这样,但是:

  • 不是标签。它说您的文档是 HTML(版本 5)。除非您知道自己在做什么,否则不应删除它。没有它,浏览器会认为您正在使用 html4,如果您仍然使用 html 5,可能会出现奇怪的想法。
  • 尝试编写更多类似 xml 的代码。例如,我尝试使用您的代码关闭 img 标签,它对我有用(最新的 chrome @ mac os):

        <div class="wall-left">
            <!-- begin wall left :: must I explain this? It opens and closes with the other wall -->
            <img src="http://www.new.gamemode.org/images/wall_left.png" />
        </div>
        <!-- end wall left -->
        <div class="wall-right">
            <!-- begin wall-right :: must I explain this? It opens and closes with the other wall -->
            <img src="http://www.new.gamemode.org/images/wall_right.png" />
        </div>
    

(请注意 img 标签以/> 结尾)

关于html - &lt;!DOCTYPE html> 破坏了我的页面!为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18987450/

相关文章:

Javascript HTML图像源没有改变

jquery - 如何添加阅读更多点击事件以仅打开一篇新闻文章?

javascript - 宽度以 px 为单位指定或不改变 Canvas 行为

javascript - 使用 jQuery 根据加载的页面将 Active 类添加到事件选项卡元素

html - 浏览器不同缩放级别的媒体查询

php - 从外部文件加载 DIV 标签

html - 文本输入字段中的 CSS 错误 - MSIE7

html - css 步骤向导 z-index 不起作用

html - 包装 div 不会为内部 div 重新调整大小

javascript - 当您调整窗口大小时图表自动缩放(使用谷歌网络应用程序制作)