Html页面与doctype变得奇怪

时间:2013-03-21 00:56:15

标签: html doctype

我写了一个html页面,在一个单独的文件中有一些css,它运行正常。然后我意识到我应该在我的html中添加一个doctype声明。我这样做了,我的页面完全搞砸了!我尝试了所有类型的声明,但最终都是相同的!!!

这是我的HTML(目前仅适用于Chrome,没有doctype):

<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <title>Luca Rood - Home</title>
    </head>
    <body background="images\background.jpg">
        <div id="header">
            <div id="header-back"></div>
            <div id="top-spacing"></div>
            <div id="content">
                <a href="index.html" title="Luca Rood - Home">
                    <img id="image" src="images\logo.png" alt="Luca Rood">
                </a>
            </div>
        </div>
    </body>
</html>

这是我的css:

body {
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 100% 100%;
    margin: 0px 0px 0px 0px;
    }

#header {
    position: relative;
    height: 15%;
    }

#header-back {
    position: absolute;
    width: 100%;
    height: 100%;
    background: #000000;
    opacity: 0.3;
    z-index:1;
    }

#top-spacing {
    height: 20%;
    width: 100%;
    }

#content {
    position: relative;
    width: 80%;
    height: 60%;
    margin-top: 0px;
    margin-bottom: 0px;
    margin-left: auto;
    margin-right: auto;
    z-index:2;
    }

#image {
    height: 100%;
    }

请帮忙。

提前致谢,

卢卡

2 个答案:

答案 0 :(得分:1)

您有经典的百分比高度问题。要解决此问题,您必须将height:100%添加到body样式,并在html元素上添加样式{<1}}:

height:100%

希望它有效!

答案 1 :(得分:-1)

试试以上&lt; html&gt;标签

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
相关问题