[英]CSS div/element position issue
我在某些div /表中遇到一些职位问题。
网站转储: http : //www.speedyshare.com/2yyuC/Screenshot-2014-11-11-at-08.58.24.png
如您在图片中所见,图像2比其他图像低。 起初,右边的菜单也较低(我想这是div造成的问题),但随后我更改为position:relativ(针对#menucontainer)(菜单的div),然后将菜单置于正确的位置。 但是如您所见,#menucontainer仍然影响2张图像。 任何想法我如何解决这个问题?
HTML:
<DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<header>
</header>
<nav>
<div id="navposition">
<div id="loggo">
<div class="loggocenter">
LodisKUNG.org
</div>
</div>
<div id="search">
<form id="searchform">
<input type="text" name="search" placeholder="Search for titles...">
<button class="submit" type="submit">Search</button>
</form>
</div>
<div id="menucontainer">
<ul>
<li id="menuhome"><a href="index.html">Home</a></li>
<li id="menuforum"><a href="index.html">Forum</a></li>
<li id="menuabout"><a href="index.html">About</a></li>
<li id="menucontact"><a href="index.html">Contact</a></li>
</ul>
</div>
</div>
</nav>
<section>
<div id="sectioncenter">
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
<div id="title">
<table>
<tr>
<th class="titlename">
The walking dead - Days gone by
</th>
</tr>
<tr>
<td class="titlepic">
<a href="#"><img src="twd.jpg" alt="twd"></a>
</td>
</tr>
</table>
</div>
</div>
</section>
</body>
</html>
CSS:
/* HTML5 CSS3 layout elements */
header {
height:30px;
background-color: #000000;
border-bottom:5px solid #c20000;
}
nav {
height:75px;
font-family: Sans-serif, Comic Sans MS;
}
section {
height:100%;
}
/* Over all CSS */
body {
margin:0px;
height:100%;
font-family: Sans-serif, Verdana;
}
/* Loggo design */
#loggo {
background-color:#c20000;
width:300px;
height:75px;
font-family: "Comic Sans MS", "Comic Sans";
font-size:35px;
color:#FFFFFF;
}
.loggocenter {
width:250px;
margin-left:auto;
margin-right:auto;
padding-top:10px;
}
/* Center section content */
#sectioncenter {
width:90%;
height:100%;
margin-left:auto;
margin-right:auto;
}
/* Center search function */
#search {
margin-left:auto;
margin-right:auto;
width:440px;
top:10px;
position:relative;
}
/* Style Navigation Menu */
#menucontainer ul {
list-style-type: none;
margin:0px;
padding:0px;
}
#menucontainer li {
display:inline;
float:left;
}
#menucontainer a {
height:100%;
width:90px;
Border-right:1px solid black;
background-color:#c20000;
display:block;
padding-left:auto;
padding-right:auto;
font-size:18px;
text-decoration:none;
text-align:center;
font-family: "Comic Sans MS", "Comic Sans";
color:#000000;
}
#menucontainer a:hover {
color:#FFFFFF;
}
#menucontainer {
float: right;
margin-bottom:1px;
position:relative;
top:-142px;
}
#navposition {
width:90%;
margin-left:auto;
margin-right:auto;
padding:0px;
height:75px;
}
#menuforum a {
background-color:green;
}
#menuabout a {
background-color:blue;
}
#menucontact a {
background-color:yellow;
}
/* Search form design */
*:focus {
outline:none;
}
#searchform input {
height:50px;
width:350px;
border-radius:5px;
font-size:20px;
font-family: "Comic Sans MS", "Comic Sans";
padding:5px;
border:3px solid black;
}
#searchform button {
font-family: "Comic Sans MS", "Comic Sans";
font-size:20px;
height:50px;
border:3px solid black;
}
/* Design looped titles */
#title {
margin-top:10px;
margin-left:5px;
float:left;
}
.titlepic img {
width:220px;
height:350px;
margin-right: auto;
margin-left: auto;
display: block;
}
#title table {
border:5px solid #f7f7f7;
border-radius:5px;
}
.titlename {
border-bottom:2px solid black;
}
很抱歉张贴整个代码,但是我不确定是不是引起问题的menucontainer,也可能是表格或其他东西。
感谢帮助!
您需要清除元素的浮动,只需将以下代码添加到section标签上方
<div style="clear:both"></div>
其作品!
搜索框将元素向下推。
给导航元素一个高度。 例如230px
您需要对元素进行一些调整。 给一些元素显示:块; 所以彼此对齐。
我刚刚添加了这个:
nav,
header {
display: block;
}
section {
display: block;
float: left;
height: 100%;
width: 100%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.