我是新來的HTML/CSS和我一直這個下拉菜單:http://cssdeck.com/labs/he8ykb8n如何創建懸停在背景圖片上的下拉菜單?
第一個問題:我試圖讓下拉菜單懸停背景圖像/幻燈片。出於某種原因,我不能那樣做。
這就是我想要實現的:http://bildeopplaster.no/3qi所以下拉菜單是懸停在背景圖片上。
第二個問題:另外,如果您可以在上面的演示中看到您只有「男裝」按鈕。我試圖複製代碼,只是改變按鈕名稱,所有按鈕都可以在圖片上顯示,但代碼沒有對齊「男裝」按鈕旁邊的新按鈕。有沒有什麼辦法可以修復,這樣我就可以使用相同的懸停效果獲取所有按鈕?在導航欄
HTML代碼:導航欄
<nav class="navigation">
<ul>
<li class="menubar"><a href="#">MEN'S WEAR</a>
<ul>
<li class="dropdown"><a href="#">TOPWEAR</a>
<ul>
<li><a href="#">Jackets & Coats</a></li>
<li><a href="#">Shirts</a></li>
<li><a href="#">Overshirts</a></li>
<li><a href="#">T-Shirts</a></li>
<li><a href="#">Basic T-Shirts</a></li>
<li><a href="#">Knitwear</a></li>
<li><a href="#">Sweats</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">BOTTOMWEAR</a>
<ul>
<li><a href="#">Jeans</a></li>
<li><a href="#">Colour Jeans</a></li>
<li><a href="#">Pants</a></li>
<li><a href="#">Shorts</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">FOOTWEAR</a>
<ul>
<li><a href="#">Boots</a></li>
<li><a href="#">Sandals</a></li>
<li><a href="#">Shoes</a></li>
<li><a href="#">Snickers</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">ACCESSORIES</a>
<ul>
<li><a href="#">Belts</a></li>
<li><a href="#">Caps</a></li>
<li><a href="#">Hats</a></li>
<li><a href="#">Scarves</a></li>
<li><a href="#">Gloves</a></li>
<li><a href="#">Sunglasses</a></li>
<li><a href="#">Watches</a></li>
<li><a href="#">Jewelry</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">SALE</a>
<ul>
<li><a href="#">Jackets & Coats</a></li>
<li><a href="#">Shirts</a></li>
<li><a href="#">Overshirts</a></li>
<li><a href="#">T-Shirts</a></li>
<li><a href="#">Basic T-Shirts</a></li>
<li><a href="#">Knitwear</a></li>
<li><a href="#">Sweats</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li class="menubar"><a href="#">MEN'S WEAR</a>
<ul>
<li class="dropdown"><a href="#">TOPWEAR</a>
<ul>
<li><a href="#">Jackets & Coats</a></li>
<li><a href="#">Shirts</a></li>
<li><a href="#">Overshirts</a></li>
<li><a href="#">T-Shirts</a></li>
<li><a href="#">Basic T-Shirts</a></li>
<li><a href="#">Knitwear</a></li>
<li><a href="#">Sweats</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">BOTTOMWEAR</a>
<ul>
<li><a href="#">Jeans</a></li>
<li><a href="#">Colour Jeans</a></li>
<li><a href="#">Pants</a></li>
<li><a href="#">Shorts</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">FOOTWEAR</a>
<ul>
<li><a href="#">Boots</a></li>
<li><a href="#">Sandals</a></li>
<li><a href="#">Shoes</a></li>
<li><a href="#">Snickers</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">ACCESSORIES</a>
<ul>
<li><a href="#">Belts</a></li>
<li><a href="#">Caps</a></li>
<li><a href="#">Hats</a></li>
<li><a href="#">Scarves</a></li>
<li><a href="#">Gloves</a></li>
<li><a href="#">Sunglasses</a></li>
<li><a href="#">Watches</a></li>
<li><a href="#">Jewelry</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">SALE</a>
<ul>
<li><a href="#">Jackets & Coats</a></li>
<li><a href="#">Shirts</a></li>
<li><a href="#">Overshirts</a></li>
<li><a href="#">T-Shirts</a></li>
<li><a href="#">Basic T-Shirts</a></li>
<li><a href="#">Knitwear</a></li>
<li><a href="#">Sweats</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
CSS代碼:
.navigation {
position: relative;
background-color: #ddd;
width: 1024px;
height: 42px;
margin: 0 auto;
-webkit-font-smoothing:antialiased;
}
.navigation a {
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.menubar ul {
opacity: 0;
position: relative;
top: 0px;
visibility: hidden;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.menubar {
position: relative;
list-style: none;
display: inline;
}
.menubar a {
text-decoration: none;
position: relative;
top: 12px;
right: 40px;
font-weight: bold;
padding: 12px 15px 11px 15px;
}
.menubar a:nth-child(1) {
color: #000;
list-style: none;
}
.menubar a:hover:nth-child(1) {
color: #fff;
background: #000;
}
.menubar:hover ul {
visibility: visible;
opacity: 1;
}
.menubar li{
background: transparent;
}
.dropdown:nth-child(1) {
float: left;
background: #000;
position: relative;
list-style: none;
top: 22px;
right: 80px;
padding-bottom: 96px;
padding-left: 40px;
padding-top: 1px;
margin-right: -20px;
}
.dropdown:nth-child(2) {
float: left;
background: #000;
position: relative;
list-style: none;
top: 22px;
right: 60px;
padding-bottom: 200px;
padding-left: 40px;
padding-top: 1px;
margin-right: -20px;
}
.dropdown:nth-child(3) {
float: left;
background: #000;
position: relative;
list-style: none;
top: 22px;
right: 40px;
padding-bottom: 200px;
padding-left: 40px;
padding-top: 1px;
margin-right: -20px;
}
.dropdown:nth-child(4) {
float: left;
background: #000;
position: relative;
list-style: none;
top: 22px;
right: 20px;
padding-bottom: 63px;
padding-left: 40px;
padding-top: 1px;
margin-right: -20px;
}
.dropdown:nth-child(5) {
float: left;
background: #000;
position: relative;
list-style: none;
top: 22px;
right: 20px;
left: 0px;
padding-bottom: 100px;
padding-left: 42px;
padding-right: 20px;
padding-top: 1px;
}
.dropdown a {
right: 10px;
position: relative;
top: 10px;
left: -40px;
font-weight: bold;
color: #888;
}
.dropdown a:hover {
text-decoration: underline;
color: #fff;
}
.dropdown a:nth-child(1) {
color: #cbcbcb;
}
.dropdown ul {
list-style: none;
display: inline;
position: relative;
padding: 15px;
}
.dropdown ul li {
position: relative;
padding: 8px;
top: 5px;
right: 5px;
font-size: 13.5px;
}
.dropdown ul li a {
font-weight: normal;
}
這就是當我將上面的代碼插入主代碼時的樣子:http://bildeopplaster.no/3qj如果我將鼠標懸停在「男裝」按鈕上,下拉菜單可見,但黑色背景如圖所示,即使我沒有將鼠標懸停在按鈕上 – Nohman