gpt4 book ai didi

html - CSS float 属性

转载 作者:行者123 更新时间:2023-11-28 08:12:20 25 4
gpt4 key购买 nike

到目前为止我的 HTML

<!DOCTYPE html> 
<html>
<head>
<title>Home</title>
<meta charset="UTF-8">
<style type="text/css" title="currentStyle" media="all">@import url(css/general.css);
</style>
</head>

<body>
<div id="container">
<div id="header"></div>
<div id="line"></div>
<div id="navigation">
<ul>
<li><a href="#">TV Shows</a></li>
<ul>
<li><a href="#">The Walking Dead</a></li>
<li><a href="#">Grimm</a></li>
</ul>
<li><a href="#">Movies</a>
<ul>
<li><a href="#">Action</a>
<li><a href="#">Comedy</a></li>
<li><a href="#">Thriller</a></li>
</ul>
</ul>
</div>
<div id="content">
<p>some text blablablaba</p>
</div>
<div id="footer"></div>
</div>
</body>
</html>

我的 CSS

#container
{
border: 1px solid black;
width:95%;
height: 800px;
margin: 0 auto;
}
#line
{
border: 1px solid black;
position: relative;
top: 100px;
}

#header
{
background: url(../header.jpg) no-repeat;
width:150px;
height:150px;
float: left;
position: relative;
top: 50px;
left: 100px;
border: 1px solid black;
z-index: 30;

}

#navigation
{
position: relative;
float:left;
top: 270px;
width: auto;
height: auto;
border: 1px solid black;
}

#content
{
float:right;
top: 270px;
width: auto;
height: auto;
border: 1px solid black;
}

我的问题:如果我将内容框向右或向左浮动,为什么我的内容框会停留在页面顶部?我在 float 上读到的内容应该填满导航旁边的空间。 (因为我的行 div 在页面上传播。)我希望我的内容位于导航旁边的相同位置。

(ps. 没有样式但布局简单 atm)

编辑:将我的 class="content"错误编辑为 id="content"问题仍然存在

最佳答案

你用过

#content
{
...
}

class='content'!?

你应该使用.content

并为.content设置position: relative;

jsfiddle

关于html - CSS float 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29195936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com