Question

I have a drop Down Menu, which when clicked upon, pushes the content below it to make space for its items. However I would like for the drop down to overlap the contents below without pushing it down.

I tried a couple of things but they didnt work including z-index:1; on the drop down list.

  <td valign="top" class="navigationLink" style="width: 20%" >

                    <div class="reportDiv">
                        <h:outputLabel value="Report" rendered="#{welcomeBean.report}" class="reportMenu"/>


                        <ul class="reportUL" >
                            <li><h:link value="Project Wise Report" outcome="/webpages/ProjectWiseReport.xhtml" rendered="true" class="reportItems"/></li>
                            <li><h:link value="Employee Wise Report" outcome="/webpages/EmployeeWiseReport.xhtml" rendered="true" class="reportItems"/></li>
                        </ul>
                    </div>
                    </td>    

This is the drop down. This forms one row of the table in which i have placed the contents of the webpage. When i click on My Account label, the ul drops down and the height of the table's row increases and pushes the row below it down. I would like for the drop down to overlap the next row contents. How should i do that?

Some more code below and above it

 <div class="container">
            <!-- this is where the webpages starts from. The below table is where the main contents are  -->
            <table  border="0" cellpadding="2" style="width: 100%; ">

                <tr style="background-color: #95D0CA;">
                  <!-- contains header of page -->
                    <td colspan="2">
                   </td>
                </tr>

           <tr style=" position: relative; z-index:1;">
            <td colspan="2" valign="top">

       <!-- THIS IS WHERE I HAVE ADDED A NEW TABLE TO CONTAIN THE MENU ITEMS. THE DROP DOWN IS A (td) OF THIS TABLE -->       

         <table border="0" cellspacing="2" cellpadding="2" class="templateBody" style="width: 100%;">

                <tr >

               <td> 
                     <!-- other menu items -->
              </td>

             <!-- DROP DOWN -->
               <td valign="top" class="navigationLink" style="width: 20%" >

                    <div class="reportDiv">
                        <h:outputLabel value="Report" rendered="#{welcomeBean.report}" class="reportMenu"/>


                        <ul class="reportUL" >
                            <li><h:link value="Project Wise Report" outcome="/webpages/ProjectWiseReport.xhtml" rendered="true" class="reportItems"/></li>
                            <li><h:link value="Employee Wise Report" outcome="/webpages/EmployeeWiseReport.xhtml" rendered="true" class="reportItems"/></li>
                        </ul>
                    </div>
                    </td>    


                     </tr> 
              </table>
           </td>
        </tr> 


         <!-- NOW the Row which gets pushed down appears -->
        <tr>

           <td  colspan="2" valign="top"  style="width: 100%">

             <div class="contentBody">

             </div>

          </td>
        </tr> 

      </table>
        </div>      

I will show some snaps of how it looks. This might guide you guys to understand my problem.

Below an image of before drop down expands: !(http://imgur.com/QauRGVc)

image after drop down expands: !(http://imgur.com/VMlcCbp)

I have tried using jsFiddle as many of you suggested, but it wasnt showing my code as it is. So that was not serving the purpose. I hope this edit helps.

Please Help me. And do let me know if you need additional codes. ** Thank You in Advance :)**

**Edit**

Adding CSS and JAVA SCRIPT CODES

CSS CODE for the code i have provided

 .navigationLink a
 {
  background-color: #95D0CA;
  margin-top: 5px;
  margin-bottom: 5px;
 }

 .navigationLink label
 {
 background-color: #95D0CA;
  margin-top: 5px;
 margin-bottom: 5px;
 }


   .reportMenu
   {
   text-decoration: none;
    color: #216961;
   font-weight: bold;
   font-size: 15px;
   display: block;
   padding: 10px 5px 10px 5px;
   text-align: center;  
   cursor: pointer;
   }

 .reportItems
 {
    color: white; 
    text-decoration: none;
    font-weight: 400;
    font-size: 15px;
    padding: 10px;
   background-color: #95D0CA;
   text-align: center;
 }

  .container
  {
   width: 1000px;
   background-color: whitesmoke;
   padding: 10px;
   margin: 50px auto;
   position: relative;
  }

 .templateBody
 {
    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
    width: auto;
 }

 .templateBody td
 {
    text-align:center;
 }

 .contentBody
 {
    background-color: whitesmoke;           
    margin: 10px 0px 10px 0px;
    width: 100%;
    position: relative;
    clear: both;
 }

   .reportUL
 {
   list-style-type: none;
    position: absolute;
   z-index: 1;
    padding: 0;
   margin: 0;
   text-align: left;

 }

 .reportUL li
 {
  background-color: #95D0CA;
 }

JQUERY CODE

           $(document).ready(function()
    {   
        $(".img, #img").show();
        $("#loginWindow").hide();
        $("#loginSlide").show();
       $(".reportItems").hide();
         $(".reportItems1").hide();

        $("#loginSlide").click(function()
        {
            $("#loginWindow").slideToggle(200);
        });
        $(".toDate").datepicker();

        $(".fromDate").datepicker();

       $( "#accordion" ).accordion({
          collapsible: true
        });



        $(".reportDiv").hover(function()
        {
            $(".reportItems").slideToggle(150);
        });

        $(".accountDiv").hover(function()
        {
            $(".reportItems1").slideToggle(150);
        });


        $(".mainLinks, .reportMenu, .reportItems, .reportMenu1, .reportItems1  ").hover(function()
        {
            $(this).css({"text-shadow":"0px 0px 5px #FFFFFF"});
        }, function(){
            $(this).css("text-shadow","none");
        });



    });
Was it helpful?

Solution 2

I just need to add the following CSS properties to the class reportUL of the the un-ordered list (ul) i used to add the drop down menu:

the property required to overlap the drop down on the contents below is:

 position: absolute;

and to make it show above / on top of the below content i used:

z-index: 1;

the complete and correct CSS for the class is:

     .reportUL
{
   list-style-type: none;
    position: absolute;
   z-index: 1;
    padding: 0;
   margin: 0;
   text-align: left;

}

OTHER TIPS

Take a look at following fiddles.

These are some nice drop down menu's you can build

Fidde 1

Fiddle 2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top