2016-10-10 4 views
-2

저는 CSS를 사용하여 드롭 다운 메뉴를 만드는 방법에 대한 온라인 비디오를 보았습니다. 나는 그것을 따라 갔고 내 웹 사이트에는 드롭 다운 메뉴의 흔적이 없다. 그것은 내가 백엔드 dev에 지금 집중할 수 있도록 그것을 극복하고자하기 때문에 너무 실망 스럽다. 당신이 이걸 알아낼 수 있기를 바랍니다. HTML에 대한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> 

코드 :

@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

심각하게? -삼?? 롤! 여기에 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 속성을 사용하면 실제로 숨기고 있으며, 메뉴 요소를 가리키면 열립니다 (그대로 있어야 함). 그 다음으로 #nav_menu li:hover .sub-menu의 코드 opacity: 1;을 변경 display: none;

:

는 당신하여 .sub-menu 클래스의 opacity: 0;를 교체해야,이 작업을 수행하려면 display: block; (코드에서 내가 전에 준).

opacity으로 처리하는 것보다 더 청결합니다.

+0

입니다. 마침내! – BrunoEarth

+0

질문이 하나 더 있는데 드롭 다운 메뉴가 내 이미지 슬라이더 바로 뒤에 있습니다. 드롭 다운 메뉴가 이미지 슬라이더 위에 오도록 코드를 추가 할 수 있습니까? – BrunoEarth

+0

귀하의 웹 사이트의 작동 예제를 볼 수 없기 때문에 정확하게 말할 수는 없지만, 자바 스크립트 슬라이더가 슬라이드의 일부 'z- 인덱스'를 추가하고있는 것 같습니다. '.sub-menu '안에'z-index'를 추가해야합니다. 또 다른 요점은 드롭 다운 메뉴를 다르게 처리해야하며 대답을 편집하는 방법에 대해 설명하겠습니다. – Cladiuss

관련 문제