0

I am trying to create a html dropdown list which should be on top of other divs when selected, but it moves the below div s down and make them be there after selecting dropdown item. Code I tried is in fiddle here. How can I make dropdown float on below div s on selection?

<div class="outer" >  
       <select id="myselect" style="width:100px;">
           <option>abc</option>
           <option>def</option>
           <option>ghi</option>
           <option>jkl</option>
          <option>abc</option>
           <option>def</option>
           <option>ghi</option>
           <option>jkl</option>

    </select>
</div>
   <div class="inner">Enter Name</div>
   <div class="inner">Enter Class</div>

</div>

 $('#myselect').on('mousedown focus', function () {
                    $('#myselect').attr('size', 11);
                    $('#myselect').css('height', '80px');
                    $('.outer').css('height', '80px');
     $('.outer').css('overflow-y', 'scroll');
                });


   $('#myselect').on('change', function () {
                    $('#myselect').attr('size', '1');
                    $('#myselect').css('height', '20px');                    
                });

3 Answers 3

2

If what you want is to keep the dropdown on top of the div try setting the position of the dropdown to absolute

$('.outer').css('position', 'absolute');

JS Fiddler

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

5 Comments

Sorry, I just realized that you mentioned that in your question. I'll update the answer
Leo, This code is really great. But once I select the dropdown the bottom content is moving up. and controls next to that dropdown are merging with selected dropdown. Could you please fix this so that I can mark your answer.
It's a bit hard to understand what you want but try this updated fiddler
Please check my jsfiddle.net/RK6EF/34 to get more details. The right controls will be moving to left as position is absolute.
mate this JS Fiddler is different to the one provider in your question...sorry, I don't think anybody can help if you keep changing your question
1

You should reset the height of the .outer as shown below:

            $('.outer').css('height', 'auto');

See http://jsfiddle.net/RK6EF/8/ for fix

3 Comments

By 'make dropdown float on below div s on selection' do you mean to say that you want the select drop down to hide the two divs on expanding?
On selecting dropdown, I am trying to have dropdown on top of below divs.
Could you please add this as answer?
1

You will have to use position:absolute if you want elements to overlap Overlapping elements in CSS

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.