2016-10-10 15 views
-2

私はcssを使ってドロップダウンメニューを作成する方法についてこのビデオをオンラインでフォローしてきました。私はそれに続き、私のウェブサイトにはドロップダウンメニューの兆候はありません。私はバックエンド開発者に焦点を当てることができるので、私はそれを乗り越えたいので、とてもイライラしています。皆さんがこれを理解できることを願っています。 CSSのためのCSSドロップダウンメニューが機能しませんか?

<!DOCTYPE> 
    <html lang="en"> 
<head> 
<title>MUSIC STORE</title> 

<script src="js/jquery-1.11.2.min.js"></script> 


<link rel="stylesheet" href="jquery.bxslider.css"/> 
<link rel="stylesheet" href="styles.css"/> 
<link rel="shortcut icon" type="image/png" href="../Music Store/img/rockSign.png"/> 
</head> 

<body> 
    <div id="wrapper"> 
     <header id="main_header"> 
      <div id="callout"> 
       <h2>&#9742; 111222333</h2> 
       <p>Michigan State Kawasaki Iceland</p> 
      </div> 
      <h1>MUSIC STORE</h1> 
     </header> 

     <div class="clearfix"></div> 

     <nav id="nav_menu"> 
      <ul id="nav"> 
       <li><a href="#">HOME</a></li> 
       <li><a href="#">INSTRUMENTS</a> 
        <ul class="sub-menu"> 
         <li><a href="#">ELECTRIC GUITARS</a></li> 
         <li><a href="#">BASS GUITARS</a></li> 
         <li><a href="#">DRUMS</a></li> 
        </ul> 
       </li> 
       <li><a href="#">AMPLIFIERS</a></li> 
       <li><a href="#">ACCESSORIES</a></li> 
       <li><a href="#">FEATURED ARTISTS</a></li> 
      </ul> 
     </nav> 

     <script src="js/jquery.bxslider.min.js"></script><!--For Image Slider--> 
     <div class="slide-wrap"> 
      <div class="slider"> 
       <ul class="slider1"> 
        <li><img src="../Music Store/img/ibanez.jpg"/></li> 
        <li><img src="../Music Store/img/raven.jpg"/></li> 
        <li><img src="../Music Store/img/metallica.jpg"/></li> 
       </ul> 
      </div> 
     </div> 
     <script type="text/javascript"> 
     $('.slider1').bxSlider({ 
      mode: 'fade', 
      captions: false, 
      auto:true, 
      pager:false, 

      }); 
     $('.slider2').bxSlider({ 
      pager:false, 
      captions: true, 
      maxSlides: 3, 
      minSlides: 1, 
      slideWidth: 230, 
      slideMargin: 10 
      }); 
     $('.slider3').bxSlider({ 
      mode: 'fade', 
      captions: false, 
      auto:true, 
      pager:false, 
      controls:false, 
      }); 
     </script>  


     <section class="one-third"> 
      <div class="border_section"> 
       <h3>NEW BASS AMPS THIS YEAR</h3> 
       <img src="../Music Store/img/fender_amps_bassbreaker.jpg"/> 
       <p>We would like to proudly announce the new shipment of fender bass amps that you all have been 
       waiting for. It will provide you that rich rock and roll tone like no other. Please check 
       out our bass amp section for more details.</p> 
      </div> 

     </section> 

     <section class="one-third"> 
      <div class="border_section"> 
       <h3>NEW FEATURE ARTIST</h3> 
       <img src="../Music Store/img/feature_markHolcomb.jpg"/> 
       <p>Behold Mark Holcomb from Periphery is in the house! Check out his info and new signature guitar 
       at our feature artists section. He will also be having a 20-minute guitar clinic on Oct 8 2016 right 
       here at Music Store.</p> 
      </div> 
     </section> 

     <section class="one-third"> 
      <div class="border_section"> 
       <h3>ATTENTION VOCALISTS!</h3> 
       <img src="../Music Store/img/GoMic.jpg"/> 
       <p>Check out the new Samson Go Mic Connect. It has a top-notch noise cancellation feature that can 
       definitely minimize the annoying sound that your dog makes while your recording. For more details, 
       Go to Accessories section.</p> 
      </div> 
     </section> 

     <div class="clearfix"></div> 

     <footer> 
      <p>&copy;All Rights Reserved</p> 
     </footer> 
    </div> 
    </body> 
</html> 

コード:

HTMLのコード

@import url(http://fonts.googleapis.com/css?family=Black+Ops+One:400,700); /*--- Header --*/ 
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700); /*---  Navigation --*/ 

* 
{ 
margin: 0; 
border: 0; 
padding: 0; 
} 

body 
{ 
background-image: url('../Music Store/img/background.png'); 
background-repeat: repeat-x; 

} 

.clearfix 
{ 
clear:both; 
} 

#wrapper 
{ 
margin: 0 auto; 
max-width: 1120px; 
overflow: auto;  
border: 1px solid black; 
} 

#main_header 
{ 
width: 100%; 
font-family: 'Black Ops One', sans-serif; 
background-color: black; 
border: 1px solid black; 
color: white; 
} 

#main_header h1 
{ 
float: left; 
font-size: 380%; 
margin: -10% 0 0 2%; 

} 

#callout 
{ 
margin: 50px 20px 0 0; 
} 

#callout h2{ 
text-align: right; 
color: white; 
} 

#callout p{ 
text-align: right; 
padding: 0%; 
color: grey; 
font-size: 20px; 
margin-bottom: 3px; 
} 

#nav_menu 
{ 

width: 100%; 
height: 10%; 
background-color: white; 
} 

#nav_menu li 
{ 
display: inline-block; 
margin: 20px 20px 20px 63px; 
font-family: 'Open Sans', sans-serif; 
font-size: 20px; 
font-weight: bold; 
} 

#nav_menu li a 
{ 
text-decoration: none; 
color: black; 
} 

#nav_menu li a:hover 
{ 
color: grey; 
} 

.sub-menu 
{ 
position: absolute; 
background-color: black; 
list-style-type: none; 
width: 124px; 
padding-left: 0px; 
margin-left: -25px; 
padding-top: 5px; 
opacity: 0; 
} 

.sub-menu li 
{ 
padding-left: 25px; 
padding-top: 5px; 
padding-bottom: 5px; 
} 

#nav_menu li:hover .submenu 
{ 
opacity: 1; 
} 

.sub-menu li:hover 
{ 
color: green; 
background-color: yellow; 
} 

/*--- Start Image Slider --*/ 
.slider{ 
max-width: 1120px; 
box-shadow: 1% 2% 5% 0 rgba(0, 0, 0, 0.07); 
} 

.slider1 img{ 
width: 100%; 
margin: 0 auto; 
} 

.slider .bx-wrapper .bx-controls-direction a{ 
outline: 0 none; 
position: absolute; 
text-indent: -9999px; 
top: 40%; 
height: 71px; 
width: 40px; 
z-index: -1; 
transition: all 0.7s; 
} 

.slider .bx-wrapper:hover .bx-controls-direction a{ 
z-index: 5; 
} 

.slider .bx-wrapper .bx-prev{ 
background: url("../Music Store/img/arrow_left.png") no-repeat 7px 9px; 
left: 0px; 
} 

.slider .bx-wrapper .bx-prev:hover{ 
background: url("../Music Store/img/arrow_left.png") no-repeat 8px 15px; 
} 

.slider .bx-wrapper .bx-next{ 
background: url("../Music Store/img/arrow_right.png") no-repeat 10px 12px; 
right: 0px; 
} 

.slider .bx-wrapper .bx-next:hover{ 
background: url("../Music Store/img/arrow_right.png") no-repeat 10px 17px; 
} 

/*--- End Image Slider --*/ 

.one-third img{ 
text-align: center; 
max-width: 100%; 
height: auto; 
opacity: 0.9; 
} 

.border_section p{ 
font-family: 'Lato', sans-serif; 
padding: 2%; 
color: white; 
text-align: justify; 
} 

.border_section h3 
{ 
font-family: 'Open Sans', sans-serif; 
text-align: center; 
color: white; 
text-transform: uppercase; 
letter-spacing: 1%; 
} 

.border_section 
{ 
border: 1px solid black; 
background-color: black; 
} 


.one-third{ 
width: 27.35%; 
float: left; 
margin: 2% 0 3% 4.5%; 
text-align: center; 
background-color: white; 
} 

footer{ 
font-family: 'Open Sans', sans-serif; 
font-weight: bold; 
text-align: center; 
width: 100%; 
height: 6%; 
background-color: black; 
overflow: auto; 
} 

footer p 
{ 
margin-top: 1%; 
color: white; 
} 
+0

真剣に? -3?笑!ここではCSSのフリークからたくさんの憎しみを得ました。それは – BrunoEarth

答えて

1

は、あなたのCSSにこれを追加: それはあなたが望む結果を持っているのに役立ちます。もちろん、あなたの好みについてはまだ適応があります。

/* Without this line, the submenu elements are black on black background */ 
#nav_menu .sub-menu li a { 
    color: #fff; 
} 
/* With this line you will remove the opacity:0; of the submenu when you hover the parent li */ 
#nav_menu li:hover .sub-menu { 
    opacity: 1; 
} 
/* Don't set a width so you have a better output */ 
#nav_menu li .sub-menu { 
    width: auto; 
} 
/* This lines make the submenu li dislay verticaly and not inline */ 
#nav_menu li .sub-menu li { 
    display: block; 
} 

編集:

代わりのサブメニューを表示/非表示するopacityプロパティを変更するには、displayプロパティを使用する必要があります。 現在、サブメニューは透過的ですが、常に開いています。メニューの高さが大きかった場合は、スライドを開いたときにスライド上のマウスをホバーすることで開くことができます。 displayプロパティを使用すると、実際には非表示になり、メニュー要素をホバーした場合にのみ開くことができます。これを行うには

、あなたがして.sub-menuクラスのopacity: 0;を交換する必要があります(コードに私が前にあなたを与えた)display: block;:その後で#nav_menu li:hover .sub-menuでコードopacity: 1;を変更display: none;

opacityで処理するよりもきれいです。

+0

です。最後に! – BrunoEarth

+0

もう1つ質問があります。ドロップダウンメニューは画像スライダのすぐ後ろにあります。ドロップダウンメニューがイメージスライダーの上にくるように、どのようなコードを追加できますか? – BrunoEarth

+0

私はあなたのウェブサイトの実際の例を見ることができないので、私はあなたに正確に言うことはできませんが、私はjavascriptスライダがスライドのどこかに 'z-index'を追加していると思います。 '.sub-menu'の中に' z-index'を追加してみてください。 別のポイントは、ドロップダウンメニューを別の方法で処理する必要があります。回答の編集について説明します。 – Cladiuss

関連する問題