position:绝对div在位置内消失:相对

时间:2021-10-05 20:32:14

I am relatively new to CSS .And I am facing the following problem in my page lay out .

我对CSS比较新。我在页面布局中面临以下问题。

I have looked at other posts but could not find an answer . The problem is when I specify

我看了其他帖子但找不到答案。问题是我指定的时候

position:absolute within #logo #logoimg it does not load . However If I remove

position:#logo #logoimg中的绝对值,它不加载。但是如果我删除

position:absolute #logoimg is loaded correctly . I am trying to learn how to position divs by

position:绝对正确加载#logoimg。我正在努力学习如何定位div

creating absolute divs within relative divs .

在相对div中创建绝对div。

My html

我的HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>New Web Project</title>
        <link rel="stylesheet" href="style.css" type="text/css" media="screen"  charset="utf-8"/>
    </head>
    <body>
        <div id = "wrapper">
            <div id = "header"> <img  src="images/banner.png" /> </div>
            <div id = "content">
                <div id="logo">
                    <div id="logoimg" > czcz </div>
                </div>
            </div>
        </div>
    </body>
</html>

My CSS

我的CSS

body {
  margin: 0;
  padding: 0;
}


#header {
    background: url('images/banner_tile.jpg') ;
    height: 96px;
    width: 100% ;
}

#header img {
    display:block;
    margin: auto ;
}

#content img {
    display:block;
    margin: auto ;
}

#content {
    /*overflow:auto ;*/
    background: url('images/body_tile.png') ;
    height: 100% ;  
    width: 100%  ;
}

 #logo { position:relative; height: 100px ; }

 #logo #logoimg {
    position:absolute ; 
    top:300px ;
    left:700px ;
    width:398px ;
    height:200px ;
    background: url('images/body_sprite.png');
    z-index: 1;
 }

1 个解决方案

#1


0  

A tidy fiddle with monkeys for you to play with: http://jsfiddle.net/TjQLf/

一个整洁的小提琴,供你玩猴子:http://jsfiddle.net/TjQLf/

#1


0  

A tidy fiddle with monkeys for you to play with: http://jsfiddle.net/TjQLf/

一个整洁的小提琴,供你玩猴子:http://jsfiddle.net/TjQLf/