這可能(希望)是一個非常簡單的問題,但我似乎無法得到它的工作,所以我會轉向這裏的專家。我使用了一個非常簡單的CSS下拉菜單,僅包含一個小的JQuery。問題在於,當我將鼠標懸停在下拉菜單上並打開時,它將頁面上的所有內容都壓縮到下面,而不是打開它。我試圖搞亂z-index,但這似乎不是問題。任何提示將是太棒了,在此先感謝。CSS下拉菜單推動頁面內容下降
這裏是HTML;對不起,這不是非常漂亮,我不得不撕掉一堆東西,使其簡單和通用。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML style="zoom: 100%; ">
<HEAD>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js" type="text/javascript"></script>
</HEAD>
<BODY class="bodyclass" style="background:#BCE2F1; height: 100%;">
<DIV id="maincontainer" style="min-height: 100%;">
<STYLE type="text/css">
#cssdropdown, #cssdropdown ul { font-size: 9pt; background-color: black; list-style: none; }
#cssdropdown, #cssdropdown * { padding: 0; margin: 0; }
#cssdropdown li.headlink { width: 140px; float: left; margin-left: -1px; border: 1px black solid;
background-color: white; text-align: center; }
#cssdropdown li.headlink a { display: block; color: #339804; padding: 3px; text-decoration: none; }
#cssdropdown li.headlink a:hover { background-color: #F8E0AC; font-weight: bold; }
#cssdropdown li.headlink ul { display: none; border-top: 1px black solid; text-align: left; }
#cssdropdown li.headlink:hover ul { display: block; text-decoration: none; }
#cssdropdown li.headlink ul li a { padding: 5px; height: 15px; }
#cssdropdown li.headlink ul li a:hover { background-color: #CCE9F5; text-decoration: none; font-weight: normal; }
/* #cssdropdown a { color: #CCE9F5; } */
#cssdropdown ul li a:hover { text-decoration: none; }
#cssdropdown li.headlink { background-color: white; }
#cssdropdown li.headlink ul { background-color: white; background-position: bottom; padding-bottom: 2px; }
</STYLE>
<SCRIPT language="JavaScript">
$(document).ready(function(){
$('#cssdropdown li.headlink').hover(
function() { $('ul', this).css('display', 'block'); },
function() { $('ul', this).css('display', 'none'); });
});
</SCRIPT>
<DIV class="navigation_box" style="border: none;">
<DIV class="innercontent">
<DIV style="background: white; float: left; padding: 5px; border: solid 1px black;">
LOGO
</DIV>
<DIV class="navmenu" style="float: right; bottom: 0; font-size: 9pt; text-align: right;">
<SPAN>Logged in as [email protected]</SPAN><BR>
<UL id="cssdropdown">
<LI class="headlink">
<A href="http://localhost:3000/one">One</A>
<UL style="display: none; ">
<LI><A href="http://localhost:3000/one">Option One</A></LI>
<LI><A href="http://localhost:3000/one">Option Two</A></LI>
<LI><A href="http://localhost:3000/one">Option Three</A></LI>
<LI><A href="http://localhost:3000/one">Option Four</A></LI>
</UL>
</LI>
<LI class="headlink">
<A href="http://localhost:3000/two">Two</A>
<UL style="display: none; ">
<LI><A href="http://localhost:3000/two">Option Two-One</A></LI>
<LI><A href="http://localhost:3000/two">Option Two-Two</A></LI>
<LI><A href="http://localhost:3000/two">Option Two-Three</A></LI>
</UL>
</LI>
<LI class="headlink" style="width: 80px;">
<A href="http://localhost:3000/three">Three</A>
</LI>
<LI class="headlink" style="width: 300px; padding-top: 2px; height: 19px;">
<FORM action="http://localhost:3000/search" method="post">
<P>
Search:
<INPUT id="searchwords" name="searchwords" size="20" type="text" value="">
<INPUT name="commit" type="submit" value="Find">
</P>
</FORM>
</LI>
<LI class="headlink" style="width: 60px;">
<A href="http://localhost:3000/four">Four</A>
</LI>
<LI class="headlink" style="width: 60px;">
<A href="http://localhost:3000/logout">Logout</A>
</LI>
</UL>
</DIV>
</DIV>
</DIV>
<DIV id="contentwrapper" style="clear:both">
<DIV class="innercontent" style="margin: 0px 20px 20px 20px;">
<H1>Some test content here to fill things out a little bit.</H1>
</DIV>
</DIV>
</DIV>
<DIV id="footer" style="clear: both; float: bottom;">
<DIV class="innercontent" style="font-size: 10px;">
Copyright 2008-2010
</DIV>
</DIV>
</BODY>
不確定您是如何收到更新的(因爲我只在我的回答中發佈了評論),所以我希望您能通過此評論獲得提醒。我編輯了我的答案,併爲您提供了一個快捷簡單的CSS + HTML版本的下拉菜單。乾杯:) – darcy 2010-04-21 18:08:05