html - 绝对定位和重叠 div

标签 html css

在我的一个 div 中包含 position:absolute 之后,我注意到(该 div)被另一个 div 重叠。

screencaps

这是我的 fiddle ,

我说的 div 是 #nav-holder 被我的页脚或 fiddle 的黑色部分重叠。

我还在我的 CSS 中使用了媒体查询。

#nav-holder { 
    position: absolute; 
    top: 0; 
    right: 0; 
    width: 200px;
}

http://jsfiddle.net/mjanthrax/pb206Lnz/

最佳答案

请更新CSS

*{box-sizing: border-box}

body, div, h1, h2, h3, h4, h5, h6, p, ul, ol, dl, dt, dd, 
img, form, fieldset, blockquote {
    margin:0 auto;
	padding:0;
}

header, footer, div{
	position: relative; 
	display: block;
}

body {
	background: #222222;
	font: 63% "Century Gothic", Tahoma, Helvetica;
}

#content {
	overflow: hidden;
	background: #eeeeee;
}

#post-wrapper{
	margin: 20px 40px 20px 40px;
	position: relative;
}

#posts {
	background: #fff;
	margin-bottom: 10px;
	padding: 10px;
	overflow: hidden;
}

#nav #list-group a#active {
	background-color: #00aadc;
	border-left-color: #00678b;
	color: #FFF;
}
#nav{
	margin: 0;
	overflow: hidden;
}

#nav #list-group {
	padding: 0;
}

#list-group{
	position: relative;
	display: block;
	padding: 10px 15px;
	margin-bottom: -1px;
	background-color: #fff;
	border: 1px solid #ddd;
}

#nav #list-group a {
	padding: 15px 10px;
	display: block;
	color: #333;
	border-left: solid 5px #FFF;
	text-decoration: none;
	font-size: 1.5em;
}

#nav #list-group a:hover {
      background-color: #e1e1e1;
      border-left-color: #e1e1e1; 
}

#posts h2 {
	font-size: 2.5em; 
	word-wrap: break-word; 
}

#posts h3, #posts h4, h5, h6 {
	padding: 4px 5px;
}

#posts h2, h3, h4, h5, h6 {
	color: #3c3f40;
}

h2#titlename{
	color: #327800;
}

#posts h3 {
	font-size: 1.8em;
}
 
#posts p {
	line-height: 1.3em; 
	font-size: 1.4em; 
}

#posts small {
	font-size: 1.2em;
	padding: 0px 5px;
}
 
#posts a {
	font-size: 1em;
	color: #327800; 
	font-weight: bold; 
	text-decoration: none; 
}
 
#posts blockquote {
	margin: 10px 20px; 
	border-left: 3px solid #cccccc; 
	padding-left: 10px; 
}
hr {
    border: 0;
    height: 1px;
    background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0)); 
    background-image:    -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0)); 
    background-image:     -ms-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0)); 
    background-image:      -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0)); 
}

/* MEDIA QUERIES */
@media screen and (min-width: 900px ) {

	#posts{
		margin-right: 220px;
	}
	
	#nav-holder { 
	    position: absolute; 
	    top: 0; 
	    right: 0; 
	    width: 200px;
  	}
    #post-wrapper{min-height:200px;}

}
<div id="content" class="container">
 		
	 	<div id="post-wrapper" >
				<div id="posts">
			<h2>test</h2>
				<small>Posted at 2015-02-28 18:35:04 by <a href="#">jarn</a></small>
				<blockquote><p><h2>test</h2></p></blockquote>
				<p id="linked"><a href="news-admin.php?postid=1">Read More</a></p>
							</div>

				
			<div id="nav-holder">
		 		<ul id="nav">
					<li id="list-group"><a href="client-information.php">Member Information</a></li>
					<li id="list-group"><a href="#" id="active">Home</a></li>
					<li id="list-group"><a href="client-loan-status.php">Loan Status</a></li>
					<li id="list-group"><a href="client-loan-history.php">Loan History</a></li>
				</ul>
	 		</div>

		</div><!--end of mainposts-->

	</div><!-- end content -->

或者您可以选择another way

关于html - 绝对定位和重叠 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28803679/

相关文章:

jquery - 下拉菜单项分布在空白区域

html - 无法在 &lt;input&gt; 标记中键入响应

html - 如何更改 HTML 仪表的背景颜色?

html - 悬停时停止文本向下移动

CSS 选项卡不能在 Bootstrap 上使用 anchor ?

html - CSS - 无法摆脱边距

javascript - HTML5 视频观看次数计数器

html - 如何在 Bootstrap 中在一行中显示输入按钮?

JQuery:设置 CSS 渐变不起作用

javascript - jQuery,如何用更少的代码将 AJAX JSON 数据加载到 html 数据元素中?