Structure & Design of FadeItems in a menu

HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="navigation_desktop">

    <div class="button_desktop_01">1.0 Main Menu
        <div class="FadeItem_01">
            <ul>
                <li>1.1 Sub Menu </li>
                <li class="button_desktop_02">1.2 Sub Menu
                    <div class="FadeItem_02">
                        <ul>
                            <li>1.2.1 Sub Menu</li>
                            <li>1.2.2 Sub Menu</li>
                        </ul> 
                    </div>
                </li> 
            </ul>
        </div>
    </div>

    <div class="button_desktop_01">2.0 Main Menu
        <div class="FadeItem_01">
            <ul>
                <li class="button_desktop_02">2.1 Sub Menu
                    <div class="FadeItem_02">
                        <ul>
                            <li>2.1.1 Sub Menu</li>
                            <li>2.1.2 Sub Menu</li>
                            <li>2.1.3 Sub Menu</li>
                        </ul> 
                    </div>
                </li> 
                <li>2.2 Sub Menu </li>
            </ul>
        </div>
    </div>  
</div>

CSS:

.button_desktop_01{
 float: left;
 position: relative;
 padding-left: 1%;
 padding-right: 1%;
 cursor: pointer;
 }

 .button_desktop_02 {
 float: left;
 position: relative;
 padding-left: 1%;
 padding-right: 1%;
 cursor: pointer;
 }

.FadeItem_01, .FadeItem_02 {
display: none
}

.FadeItem_02 {
position: absolute;
left: 100%;
top: 0;
width: 130px;
}

ul {
margin: 0;
list-style: none;
padding: 0;
}

jQuery:

$(document).ready(function() {
  $(".button_desktop_01, .button_desktop_02").mouseenter(function() {
    $(this).children(".FadeItem_01, .FadeItem_02").fadeIn(500);
  });
  $(".button_desktop_01, .button_desktop_02").mouseleave(function() {
    $(this).children(".FadeItem_01, .FadeItem_02").fadeOut(500);
  });
});

The code above FadeIn/Out some menus. The items which are under the <div class="FadeItem_02"> appear right next to the items under the <div class="FadeItem_01">. All this works perfectly so far.

I want to achieve now that the items which are under the <div class="FadeItem_02"> exactly match with the size of the button_desktop_01 (1.0 Main Menu) or button_desktop_02 (2.0 Main Menu) .

Right now they appear very close to the <div class="FadeItem_01"> which does not really look professional.

What do I have to change in my CSS to achieve this?

You can also find the code here: https://jsfiddle.net/gng5dcLc/4/

2 answers

  • answered 2017-08-12 09:50 Suresh Maurya

    you can add css

    .FadeItem_02 ul {
        padding-left: 12%; /* whatever style you want*/
    } 
    

    check this

  • answered 2017-08-12 09:50 Shiladitya

    Here you go with a solution https://jsfiddle.net/gng5dcLc/6/

    .FadeItem_02 {
      position: absolute;
      left: 110%;
      top: 0;
      width: 130px;
    }
    

    Since you are using left in CSS, thats why I updated the left to *110%** to 100%

    Hope this will help you.