Good day! There is a menu; when hovering over reports, it is necessary to display a hidden block. But for some reason it does not work.

body { margin: 0 auto; font-family: ProximaNovaRegular, sans-serif; color: #232527; background-color: #fff; } .block-white { max-width: 1170px; margin: 0 auto; } .block-black { margin: 0 auto; background-color: #f2f3f5; } .nav li { border-right: 1px solid #232527; display: inline-block; } .nav li:last-child { border: none; background: url(../img/vk.jpg) no-repeat right center; } .nav li a { padding: 10px 20px; color: #232527; font-size: 0.875rem; } .nav-fill > li:first-child { text-align: left; padding-left: 0px; } .nav-fill > li:last-child { text-align: right; padding-right: 30px; } .nav li a:hover { background-color: #d50317; color: white; text-decoration: none; } .nav-hidden { font-size: 1rem; box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); display: none; } .nav-hidden hr { height: 3px; background-color: #d50317; margin-top: 4px; } .nav-hidden .conteiner { margin-left: 15px; margin-right: 15px; } .nav-hidden a { color: #232527; } .nav-hidden a:hover { text-decoration: none; color: #d50317; } .nav-visible:hover .nav-hidden { display: block; } 
 <ul class="nav nav-fill"> <li class="nav-item"><a href="#">О фонде</a></li> <li class="nav-item"><a href="#">СМИ о нас</a></li> <li><a href="#">Наши меценаты</a></li> <li class="nav-item nav-visible"><a href="#">Отчеты</a></li> <li class="nav-item"><a href="#">Благодарности</a></li> <li><a href="#">Помочь Нам</a></li> <li class="nav-item"><a href="#">Наша группа</a></li> </ul> </div> <div class="nav-hidden"> <div class="block-big-white"> <hr> <div class="block-white"> <div class="conteiner"> <div class='row'> <div class="col-3"><a href="#">Медецинские учреждения</a></div> <div class="col-1"><a href="#">Детям</a></div> <div class="col-2 offset-2"><a href="#">Другим категориям</a></div> <div class="col-3 offset-1"><a href="#">Отчет о фин поступлениях и тратах</a></div> </div> <div class='row'> <div class="col-3"><a href="#">Социальные учреждения</a></div> <div class="col-1"><a href="#">Семьям</a></div> <div class="col-3 offset-2"><a href="#">Акты передачи гум помощи</a></div> </div> </div> </div> </div> </div> 

Bootstrap and jQuery are connected. Can you please tell us what the problem is? maybe I am doing something wrong?

    3 answers 3

    You are trying to show a div element when you hover over the li element with css, but these two elements are not related to each other. However, this can be done with jquery. First, you will need two classes: .hidden {aisplay: none} .show {aisplay: block} for the nav-hidden element, and then you need to write something like this in jqery (although this is a straightforward pipets, but for you to understand the principle) :

      ;(function($, window, document) { $('.nav-visible').on('mousemove', function() { $('.nav-hidden').removeClass('hidden').addClass('show'); }); $('.nav-visible').on('mouseout', function() { $('.nav-hidden').removeClass('show').addClass('hidden'); }); }(window.jQuery, window, document)); 

    Classes for hidden item:

     .nav-hidden { font-size: 1rem; box-shadow: 0 5px 10px rgba(0,0,0,0.2); } .hidden {display: none;} .show {aisplay: block} 

    In general, of course you should not write like this, it would be better to implement this by inserting a drop-down block into the necessary list item of the main menu, it would cost one css. For example, like this: https://www.mobila.name/post/5172c6cbb4ab3/

    ======> ANSWER TO A QUESTION FROM COMMENT I am really ashamed of this code, I will rewrite it humanly, but so far:

     ;(function($, window, document) { $('.nav-visible').on('mouseover', function() { $('.nav-hidden').css('display', 'block') .animate({opacity:1}, 400); }); $('.hidden').on('mouseleave', function() { $(this).fadeOut(300, function() { $(this).animate({opacity:0}, 100).css('display', 'none'); }); }); $('.someClassInNav').on('mouseover', function() { $('.nav-hidden').fadeOut(300, function() { $(this).animate({opacity:0}, 100).css('display', 'none'); }); }); }(window.jQuery, window, document)); 

    class for a hidden item (show and hidden classes from the previous version need to be removed):

     .nav-hidden { font-size: 1rem; box-shadow: 0 5px 10px rgba(0,0,0,0.2); opacity: 0; display: none; } 

    And you need to add another class for navigation:

     <ul class="nav nav-fill"> <li class="nav-item someClassInNav"><a href="#">О фонде</a></li> <li class="nav-item someClassInNav"><a href="#">СМИ о нас</a></li> <li class="someClassInNav"><a href="#">Наши меценаты</a></li> <li class="nav-item nav-visible"><a href="#">Отчеты</a></li> <li class="nav-item someClassInNav"><a href="#">Благодарности</a></li> <li class="someClassInNav"><a href="#">Помочь Нам</a></li> <li class="nav-item someClassInNav"><a href="#">Наша группа</a></li> </ul> 

    Whole code.

     ;(function($, window, document) { $('.nav-visible').on('mouseover', function() { $('.nav-hidden').css('display', 'block') .animate({opacity:1}, 400); }); $('.hidden').on('mouseleave', function() { $(this).fadeOut(300, function() { $(this).animate({opacity:0}, 100).css('display', 'none'); }); }); $('.someClassInNav').on('mouseover', function() { $('.nav-hidden').fadeOut(300, function() { $(this).animate({opacity:0}, 100).css('display', 'none'); }); }); }(window.jQuery, window, document)); 
     body { margin: 0 auto; font-family: ProximaNovaRegular, sans-serif; color: #232527; background-color: #fff;} .block-white { max-width: 1170px; margin: 0 auto;} .block-black { margin: 0 auto; background-color: #f2f3f5;} .nav li { border-right: 1px solid #232527; display: inline-block;} .nav li:last-child { border: none; } .nav li a { padding: 10px 20px; color: #232527; font-size: 0.875rem;} .nav-fill>li:first-child { text-align: left; padding-left: 0px;} .nav-fill>li:last-child { text-align: right; padding-right: 30px;} .nav li a:hover { background-color: #d50317; color: white; text-decoration: none;} .nav-hidden { font-size: 1rem; box-shadow: 0 5px 10px rgba(0,0,0,0.2); opacity: 0; display: none; } .nav-hidden hr { height: 3px; background-color: #d50317; margin-top: 4px;} .nav-hidden .conteiner { margin-left: 15px; margin-right: 15px;} .nav-hidden a { color: #232527;} .nav-hidden a:hover { text-decoration: none; color: #d50317;} 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!DOCTYPE html> <head> <link rel="stylesheet" type='text/css' href="css.css" /> </head> <body> <ul class="nav nav-fill"> <li class="nav-item someClassInNav"><a href="#">О фонде</a></li> <li class="nav-item someClassInNav"><a href="#">СМИ о нас</a></li> <li class="someClassInNav"><a href="#">Наши меценаты</a></li> <li class="nav-item nav-visible"><a href="#">Отчеты</a></li> <li class="nav-item someClassInNav"><a href="#">Благодарности</a></li> <li class="someClassInNav"><a href="#">Помочь Нам</a></li> <li class="nav-item someClassInNav"><a href="#">Наша группа</a></li> </ul> </div> <div class="nav-hidden hidden"> <div class="block-big-white"> <hr> <div class="block-white"> <div class="conteiner"> <div class='row'> <div class="col-3"><a href="#">Медецинские учреждения</a></div> <div class="col-1"><a href="#">Детям</a></div> <div class="col-2 offset-2"><a href="#">Другим категориям</a></div> <div class="col-3 offset-1"><a href="#">Отчет о фин поступлениях и тратах</a></div> </div> <di class='row'> <div class="col-3"><a href="#">Социальные учреждения</a></div> <div class="col-1"><a href="#">Семьям</a></div> <div class="col-3 offset-2"><a href="#">Акты передачи гум помощи</a></div> </di> </div> </div> </div> <script src="jquery-2.1.1.min.js"></script> <script src="js.js"></script> </div> </body> </html> 

    • Unfortunately, I don’t have any idea how to implement this with the help of nested lists, as it’s necessary that the text of the main menu itself and the nested one be the same width, but the design of the nested block, namely, the shadow from it should go to the full length of the browser. Thanks for the answer, helped. - Vyacheslav Guryanov
    • I can suggest using pseudo-elements as a stretching block and a shadow from it, but I need to play with styles. Although, I see nothing wrong with using js. - Ilya
    • And do not tell me how else to organize the appearance and disappearance of this unit at the time of guidance or removal of guidance? And then there is a very sharp change. I tried to apply fadeToggle, but unfortunately nothing came of it. Thank you in advance! - Vyacheslav Guryanov
    • Added in response - Ilya
    • Unfortunately, these fixes do not work. $ ('. nav-hidden'). css ('display', 'block') adds a block to the page, but it does not appear. - Vyacheslav Guryanov

    Your <li class="nav-item nav-visible"> not [right] the parent of <div class="nav-hidden"> , therefore .nav-visible:hover .nav-hidden {...} will not apply to it. Transfer <div class="nav-hidden"> directly to <li class="nav-item nav-visible"> or use javascript

      This is for example (without bootstrap), if an element is outside a block, you can call it on js / jquery

       $(".con span").click(function() { $(".generick").addClass("show"); $("js").addClass("show"); }); $("js").click(function() { $(".generick").removeClass("show"); $(this).removeClass("show"); }); 
       * { margin: 0; padding: 0; box-sizing: border-box; } .menu { display: table; width: 80%; margin: 20px auto; position: relative; } .link { display: table-cell; width: 1000px; text-align: center; height: 30px; vertical-align: middle; border-right: 1px solid; position: relative; z-index: 400; } .link span { color: blue; } .link:last-child { border-right: none; } .generick { width: 100%; height: 200px; position: absolute; border: 1px solid blue; border-top: none; left: 0; top: 0; padding-top: 50px; padding-left: 20px; display: none; z-index: 300; background: #fff; } .show { display: block; } .hide { display: none; } js { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 90; display: none; background: transparent; } 
       <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <div class="menu"> <div class="link"><span>О нас</span></div> <div class="link"><span>Прайс</span></div> <div class="link"><span>Врачи</span></div> <div class="link con"><span>Консультации</span></div> <div class="generick"> <div class='row'> <div class="col-3"><a href="#">Медецинские учреждения</a></div> <div class="col-1"><a href="#">Детям</a></div> <div class="col-2 offset-2"><a href="#">Другим категориям</a></div> <div class="col-3 offset-1"><a href="#">Отчет о фин поступлениях и тратах</a></div> </div> <div class='row'> <div class="col-3"><a href="#">Социальные учреждения</a></div> <div class="col-1"><a href="#">Семьям</a></div> <div class="col-3 offset-2"><a href="#">Акты передачи гум помощи</a></div> </div> </div> <div class="link"><span>Галерея</span></div> <div class="link"><span>Наша группа</span></div> </div> <js></js>