1

I'm trying to create a list of menu that when you hover on each it will show the other content. It is now working though yet every time you hover on each item it will create a space on the other list item.

Here's the sample code.

<ul class="test111">
    <li><span class="testCont">Another</span><a href="#" class="testmenu">Menu 1</a></li>
    <li><span class="testCont">Another1</span><a href="#" class="testmenu">Menu 2</a></li>
</ul>

CSS

.test111{
    position: fixed;
    right:0;
    margin-right:0;
}
.test111 li{
    margin-bottom: 10px;
    list-style: none;
    height:36px;
    display: block;
}
.test111 li .testCont{
    background:#0f0;
    width:100px;
    float:left;
    height: 100%;
}
.test111 li a{
    background:#0ff;
    width:50px;
    float:left;
    height: 100%;
}

JS

$('.testCont').hide();

$('.test111 li').mouseover(function(){

    $('.test111 li').removeClass('hoverME');
    $(this).addClass('hoverME');
    $('.hoverME .testCont').show();

});
$('.test111 li').mouseout(function(){
    $('.testCont').hide();
});

SAmple output here

Thank you so much

4 Answers 4

2

Just add float:right; to .test111 li a

$('.testCont').hide();

$('.test111 li').mouseover(function(){

    $('.test111 li').removeClass('hoverME');
    $(this).addClass('hoverME');
    $('.hoverME .testCont').show();

});
$('.test111 li').mouseout(function(){
    $('.testCont').hide();
});
.test111{position: fixed; right:0; margin-right:0;}
.test111 li{margin-bottom: 10px; list-style: none; height:36px; display: block;}
.test111 li .testCont{background:#0f0; width:100px; float:left; height: 100%;}
.test111 li a{background:#0ff; width:50px; float:left; height: 100%;float:right;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="test111">
    <li><span class="testCont">Another</span><a href="#" class="testmenu">Menu 1</a></li>
    <li><span class="testCont">Another1</span><a href="#" class="testmenu">Menu 2</a></li>
</ul>

Sign up to request clarification or add additional context in comments.

1 Comment

You're Welcome @justch4 .. Have a great day :-)
0

I don't know if this is what you need. But I am guessing here. Change the last line in CSS:

.test111 li a{background:#0ff; width:50px; float:right; height: 100%;}

Comments

0

Just change the css position property of test111 to relative. It should fix the problem

Comments

0

Here is a smooth variant using CSS opacity and jQuery .animate().

$(document).ready(function(){

  //$('.testCont').hide();

  $('.test111 li').mouseover(function(){


    $('.test111 li').removeClass('hoverME');
    $(this).addClass('hoverME');
    $('.hoverME .testCont').stop().animate({"opacity":1},600);


  });
  $('.test111 li').mouseout(function(){
    $('.testCont').stop().animate({"opacity":0},600);;
  });

});
.test111{
  position: fixed; 
  right:0; 
  margin-right:0;
}
.test111 li{
  margin-bottom: 10px; 
  list-style: none; 
  height:36px; 
  display: block;
}
.test111 li .testCont{
  background:#0f0; 
  width:100px; 
  float:left; 
  height: 100%;
}
.test111 li a{
  background:#0ff; 
  width:50px; 
  float:left; 
  height: 100%;
}
.testCont{
  opacity:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="test111">
  <li><span class="testCont">Another</span><a href="#" class="testmenu">Menu 1</a></li>
  <li><span class="testCont">Another1</span><a href="#" class="testmenu">Menu 2</a></li>
  <li><span class="testCont">Another1</span><a href="#" class="testmenu">Menu 3</a></li>
</ul>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.