CSS,div后面的菜单
大家好,我在使用 IE7 时遇到了问题,我的菜单总是下拉到它所在的 div 后面。
代码:(style.css)
@CHARSET "ISO-8859-1";
body { background: #fff url('images/bg.gif') repeat-x; }
#everything { width: 100%; height: auto; text-align: center; }
#bar { position: relative; float: left; background: #022c3e; width: 100%; height: 10px; }
#container { margin: 0px auto; position: relative; width: 944px; height: auto; background: black; }
#head { width: 100%; height: auto; position: relative; float: left; }
#menu { width: 100%; position: relative; float: left; }
#menu_links { position: relative; float: left; }
#menu_cont { position: relative; float: left; width: 932px; background: url('images/bgmenu.gif') repeat-x; height: 40px; }
#menu_cont ul li { z-index: 97; float: left; margin: 15px 15px 0 15px; font-family: "Arial",sans-serif; font-size: 12px; font-weight: bold; width: 5em; }
#menu_cont ul li a { color: #fff; text-decoration: none; }
#menu_cont ul li ul { margin: 0; padding: 0; position: absolute; width: 5em; left: -999em; }
#menu_cont ul li:hover ul { left: auto; z-index: 111; }
#menu_cont ul li ul li { display: block; margin: 0; padding: 0; text-align: left; width: 167px; color: #c2cfd9; font-size: 11px; background: #f9fcfe url('images/bullet.png') no-repeat center left; height: 22px; border-right: 1px #000 solid; border-left: 1px #000 solid; }
#menu_cont ul li ul .last { border-bottom: 1px #000 solid; }
#menu_cont ul li ul .cross { background: #f5f9fc url('images/bullet.png') no-repeat center left; }
#menu_cont ul li ul li a { color: #c2cfd9; display: block; padding: 5px 0 0 22px; }
#menu_rechts { position: relative; float: right; }
#main { width: 100%; float: left; position: relative; background: #fff; }
#links { width: 283px; position: relative; float: left; margin: 25px 0 0 0; }
.button { width: 259px; position: relative; margin: 0 auto; background: url('images/button.gif') no-repeat; height: 40px; }
.button p { padding: 15px 0 0 0; color: #718d99; font-family: "Verdana",sans-serif; font-size: 12px; font-weight: bold; }
.informatie { padding: 13px; color: #6f8ca2; font-size: 11px; font-family: "Tahoma",sans-serif; text-align: left; line-height: 18px; }
#midden { width: 636px; background: #f5f9fc; position: relative; float: right; margin: 25px 0 0 25px; }
#lijnboven { position: relative; float: left; width: 100%; background: url('images/border.gif') repeat-x top; }
#lijnonder { position: relative; float: left; width: 100%; background: url('images/border.gif') repeat-x bottom; }
#lijnlinks { position: relative; float: left; width: 100%; background: url('images/border.gif') repeat-y left; }
#lijnrechts { position: relative; float: left; width: 100%; background: url('images/border.gif') repeat-y right; }
#hoeklinksboven { position: relative; float: left; width: 100%; background: url('images/linksboven.gif') no-repeat top left; }
#hoekrechtsboven { position: relative; float: left; width: 100%; background: url('images/rechtsboven.gif') no-repeat top right;}
#hoekrechtsonder { position: relative; float: left; width: 100%; background: url('images/rechtsonder.gif') no-repeat bottom right;}
#hoeklinksonder { position: relative; float: left; width: 100%; background: url('images/linksonder.gif') no-repeat bottom left;}
#content { width: 100%; float: left; position: relative; }
h1 { border-bottom: 1px #dfe8ed dotted; font-family: "Verdana",sans-serif; font-size: 12px; color: #71909d; text-align: left; padding: 5px; }
#content p { font-family: "Tahoma",sans-serif; font-size: 11px; color: #02364c; }
#content .text { text-align: left; padding: 0 0 0 25px; margin: 0 0 15px 0; }
#footer { position: relative; float: left; width: 100%; height: 98px; background: url('images/footer.gif') repeat-x; }
#footer p { margin: 65px 0 0 0; color: #476e80; font-family: "Tahoma",sans-serif; font-size: 11px; }
html 文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" href="reset.css" type="text/css" />
<link rel="stylesheet" href="stijl.css" type="text/css" />
<title>The dons customs</title>
<script type="text/javascript">
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
<!--[if lte IE 8]>
<style type="text/css">
body { behavior:url("csshover.htc"); }
#menu_cont { z-index: 2; }
#menu_cont ul li ul { position: relative; z-index: 101; }
#menu_cont ul li:hover { z-index: 99; visibility: visible; position: relative; }
#menu_cont ul li { z-index: 99; }
#menu_cont ul li ul { display: block; margin: 0 0 0 -40px; }
</style>
<![endif]-->
</head>
<body>
<div id="everything">
<div id="bar"></div>
<div id="container">
<div id="head"><img src="images/head.jpg" alt="The dons customs header" /></div>
<div id="menu">
<div id="menu_links"><img src="images/menu_links.png" alt="Menu links" /></div>
<div id="menu_cont">
<ul id="nav">
<li><a href="#">Button</a></li>
<li><a href="#">Button</a>
<ul>
<li><a href="#">item 1</a></li>
<li class="cross"><a href="#">item 2</a></li>
<li class="last"><a href="#">item 3</a></li>
</ul>
</li>
<li><a href="#">Button</a></li><li><a href="#">Button</a></li>
<li><a href="#">Button</a></li><li><a href="#">Button</a></li>
</ul>
</div>
<div id="menu_rechts"><img src="images/menu_rechts.png" alt="Menu rechts" /></div>
</div>
<div id="main">
<div id="links">
<div id="flashcontent">
<script type="text/javascript" src="flash.js"></script>
</div>
<div class="button">
<p>Bedrijfsinformatie</p>
</div>
<div class="info">
<p class="informatie">
<strong>Cms name</strong>
<br /><br />
Contact persoon: Directeur Kuiper<br />
Adres: Rijksweg 100 <br />
Postcode/Plaats: 3453 AA Amsterdam<br />
Telefoon: 06 123412341<br />
<br />
KVK nummer: 012343124 <br />
BTW: NL 738593843B01
</p>
</div>
</div>
<div id="midden">
<div id="lijnboven">
<div id="lijnonder">
<div id="lijnlinks">
<div id="lijnrechts">
<div id="hoeklinksboven">
<div id="hoekrechtsboven">
<div id="hoekrechtsonder">
<div id="hoeklinksonder">
<div id="content">
<h1>Home</h1>
<br />
<p><img src="images/banner.jpg" alt="Banner auto's" /></p>
<p><br /></p>
<p class="text">Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. </p>
<p class="text">Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi.</p>
<p class="text">Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis.</p>
<br />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<p>© <strong>The Don's Customs</strong> | Alle rechten voorbehouden | Algemene voorwaarden</p>
</div>
</div>
</body>
</html>
提前致谢!
Hey guys, I'm having a problem with IE7, my menu always drops down behind the div where it's in.
The code: (style.css)
@CHARSET "ISO-8859-1";
body { background: #fff url('images/bg.gif') repeat-x; }
#everything { width: 100%; height: auto; text-align: center; }
#bar { position: relative; float: left; background: #022c3e; width: 100%; height: 10px; }
#container { margin: 0px auto; position: relative; width: 944px; height: auto; background: black; }
#head { width: 100%; height: auto; position: relative; float: left; }
#menu { width: 100%; position: relative; float: left; }
#menu_links { position: relative; float: left; }
#menu_cont { position: relative; float: left; width: 932px; background: url('images/bgmenu.gif') repeat-x; height: 40px; }
#menu_cont ul li { z-index: 97; float: left; margin: 15px 15px 0 15px; font-family: "Arial",sans-serif; font-size: 12px; font-weight: bold; width: 5em; }
#menu_cont ul li a { color: #fff; text-decoration: none; }
#menu_cont ul li ul { margin: 0; padding: 0; position: absolute; width: 5em; left: -999em; }
#menu_cont ul li:hover ul { left: auto; z-index: 111; }
#menu_cont ul li ul li { display: block; margin: 0; padding: 0; text-align: left; width: 167px; color: #c2cfd9; font-size: 11px; background: #f9fcfe url('images/bullet.png') no-repeat center left; height: 22px; border-right: 1px #000 solid; border-left: 1px #000 solid; }
#menu_cont ul li ul .last { border-bottom: 1px #000 solid; }
#menu_cont ul li ul .cross { background: #f5f9fc url('images/bullet.png') no-repeat center left; }
#menu_cont ul li ul li a { color: #c2cfd9; display: block; padding: 5px 0 0 22px; }
#menu_rechts { position: relative; float: right; }
#main { width: 100%; float: left; position: relative; background: #fff; }
#links { width: 283px; position: relative; float: left; margin: 25px 0 0 0; }
.button { width: 259px; position: relative; margin: 0 auto; background: url('images/button.gif') no-repeat; height: 40px; }
.button p { padding: 15px 0 0 0; color: #718d99; font-family: "Verdana",sans-serif; font-size: 12px; font-weight: bold; }
.informatie { padding: 13px; color: #6f8ca2; font-size: 11px; font-family: "Tahoma",sans-serif; text-align: left; line-height: 18px; }
#midden { width: 636px; background: #f5f9fc; position: relative; float: right; margin: 25px 0 0 25px; }
#lijnboven { position: relative; float: left; width: 100%; background: url('images/border.gif') repeat-x top; }
#lijnonder { position: relative; float: left; width: 100%; background: url('images/border.gif') repeat-x bottom; }
#lijnlinks { position: relative; float: left; width: 100%; background: url('images/border.gif') repeat-y left; }
#lijnrechts { position: relative; float: left; width: 100%; background: url('images/border.gif') repeat-y right; }
#hoeklinksboven { position: relative; float: left; width: 100%; background: url('images/linksboven.gif') no-repeat top left; }
#hoekrechtsboven { position: relative; float: left; width: 100%; background: url('images/rechtsboven.gif') no-repeat top right;}
#hoekrechtsonder { position: relative; float: left; width: 100%; background: url('images/rechtsonder.gif') no-repeat bottom right;}
#hoeklinksonder { position: relative; float: left; width: 100%; background: url('images/linksonder.gif') no-repeat bottom left;}
#content { width: 100%; float: left; position: relative; }
h1 { border-bottom: 1px #dfe8ed dotted; font-family: "Verdana",sans-serif; font-size: 12px; color: #71909d; text-align: left; padding: 5px; }
#content p { font-family: "Tahoma",sans-serif; font-size: 11px; color: #02364c; }
#content .text { text-align: left; padding: 0 0 0 25px; margin: 0 0 15px 0; }
#footer { position: relative; float: left; width: 100%; height: 98px; background: url('images/footer.gif') repeat-x; }
#footer p { margin: 65px 0 0 0; color: #476e80; font-family: "Tahoma",sans-serif; font-size: 11px; }
The html file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" href="reset.css" type="text/css" />
<link rel="stylesheet" href="stijl.css" type="text/css" />
<title>The dons customs</title>
<script type="text/javascript">
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
<!--[if lte IE 8]>
<style type="text/css">
body { behavior:url("csshover.htc"); }
#menu_cont { z-index: 2; }
#menu_cont ul li ul { position: relative; z-index: 101; }
#menu_cont ul li:hover { z-index: 99; visibility: visible; position: relative; }
#menu_cont ul li { z-index: 99; }
#menu_cont ul li ul { display: block; margin: 0 0 0 -40px; }
</style>
<![endif]-->
</head>
<body>
<div id="everything">
<div id="bar"></div>
<div id="container">
<div id="head"><img src="images/head.jpg" alt="The dons customs header" /></div>
<div id="menu">
<div id="menu_links"><img src="images/menu_links.png" alt="Menu links" /></div>
<div id="menu_cont">
<ul id="nav">
<li><a href="#">Button</a></li>
<li><a href="#">Button</a>
<ul>
<li><a href="#">item 1</a></li>
<li class="cross"><a href="#">item 2</a></li>
<li class="last"><a href="#">item 3</a></li>
</ul>
</li>
<li><a href="#">Button</a></li><li><a href="#">Button</a></li>
<li><a href="#">Button</a></li><li><a href="#">Button</a></li>
</ul>
</div>
<div id="menu_rechts"><img src="images/menu_rechts.png" alt="Menu rechts" /></div>
</div>
<div id="main">
<div id="links">
<div id="flashcontent">
<script type="text/javascript" src="flash.js"></script>
</div>
<div class="button">
<p>Bedrijfsinformatie</p>
</div>
<div class="info">
<p class="informatie">
<strong>Cms name</strong>
<br /><br />
Contact persoon: Directeur Kuiper<br />
Adres: Rijksweg 100 <br />
Postcode/Plaats: 3453 AA Amsterdam<br />
Telefoon: 06 123412341<br />
<br />
KVK nummer: 012343124 <br />
BTW: NL 738593843B01
</p>
</div>
</div>
<div id="midden">
<div id="lijnboven">
<div id="lijnonder">
<div id="lijnlinks">
<div id="lijnrechts">
<div id="hoeklinksboven">
<div id="hoekrechtsboven">
<div id="hoekrechtsonder">
<div id="hoeklinksonder">
<div id="content">
<h1>Home</h1>
<br />
<p><img src="images/banner.jpg" alt="Banner auto's" /></p>
<p><br /></p>
<p class="text">Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. </p>
<p class="text">Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi.</p>
<p class="text">Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis.</p>
<br />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<p>© <strong>The Don's Customs</strong> | Alle rechten voorbehouden | Algemene voorwaarden</p>
</div>
</div>
</body>
</html>
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
改成
:
change:
to:
这里的代码太多了:)
通常当涉及到下拉菜单时,我使用 Chrome 菜单。 这真的很好,节省了我很多时间。
Tooo much code here :)
Usually when it comes to dropdown menus I use Chrome Menu. It's really good and saved me a lot of time.
在制作这些东西时,我通常只使用一些固定的 CSS 模板。
对于您的情况,您可能会发现此网站很有帮助。 它建议 IE 使用此代码片段(显然不完全适合您的代码)。
祝你好运。
When making these kinds of things I often just use some fixed CSS template.
In your case you may find this site helpful. It suggests this snippet (obviously not exactly fitted for your code) for IE.
Good luck.