CSS Scrolling menu - dropdown menu doesn't scroll properly









up vote
0
down vote

favorite












I have a horizontal scrolling menu with some of the main menu items having a dropdown menu. The problem is if I scroll the main menu the drop down menus do not follow (absolute positioning), or if I make them follow (relative) they push the main menu up.



Absolute:



enter image description here



Relative:



enter image description here



The CSS is:



.navbar 
width:100%;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;


.dropdown-content
display: none; //displayed on hover
position: absolute; //or relative
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;



Any suggestions as to what I can do to fix this?



What I am looking for is the absolute version - notice the drop down menu drops over the scroll bar, not pushing it down - but with the sub menu properly aligned.



See jsfiddle for example of absolute postioning:



https://jsfiddle.net/9hjgo1qc/7/










share|improve this question



















  • 1




    Maybe provide enough sample to actually reproduce the issue first? A couple css classes isn't exactly helpful unless you're hoping someone just writes you a menu, you know this amigo...
    – Chris W.
    Nov 9 at 21:44










  • Exactly. Provide (at least) HTML to see how did you implement those menus. The catch will be there, I guess.
    – Nemanja Glumac
    Nov 9 at 21:45










  • It's not necessarily the css that is needed here, providing your HTML should be enough. That said, the problem is likely in your HTML. Your absolute positioned submenu should be inside its corresponding parent and that parent should be position: relative
    – Chaosxmk
    Nov 9 at 21:58










  • @RGriffiths ok, this is extremely ugly and I made it in few minutes, but it serves a purpose, I guess. No positioning at all needed. Once you provide jsfiddle, I can write an official answer if you wish with more sophisticated and elaborate code :) . codepen.io/anon/pen/zMBjyP
    – Nemanja Glumac
    Nov 9 at 22:06















up vote
0
down vote

favorite












I have a horizontal scrolling menu with some of the main menu items having a dropdown menu. The problem is if I scroll the main menu the drop down menus do not follow (absolute positioning), or if I make them follow (relative) they push the main menu up.



Absolute:



enter image description here



Relative:



enter image description here



The CSS is:



.navbar 
width:100%;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;


.dropdown-content
display: none; //displayed on hover
position: absolute; //or relative
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;



Any suggestions as to what I can do to fix this?



What I am looking for is the absolute version - notice the drop down menu drops over the scroll bar, not pushing it down - but with the sub menu properly aligned.



See jsfiddle for example of absolute postioning:



https://jsfiddle.net/9hjgo1qc/7/










share|improve this question



















  • 1




    Maybe provide enough sample to actually reproduce the issue first? A couple css classes isn't exactly helpful unless you're hoping someone just writes you a menu, you know this amigo...
    – Chris W.
    Nov 9 at 21:44










  • Exactly. Provide (at least) HTML to see how did you implement those menus. The catch will be there, I guess.
    – Nemanja Glumac
    Nov 9 at 21:45










  • It's not necessarily the css that is needed here, providing your HTML should be enough. That said, the problem is likely in your HTML. Your absolute positioned submenu should be inside its corresponding parent and that parent should be position: relative
    – Chaosxmk
    Nov 9 at 21:58










  • @RGriffiths ok, this is extremely ugly and I made it in few minutes, but it serves a purpose, I guess. No positioning at all needed. Once you provide jsfiddle, I can write an official answer if you wish with more sophisticated and elaborate code :) . codepen.io/anon/pen/zMBjyP
    – Nemanja Glumac
    Nov 9 at 22:06













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a horizontal scrolling menu with some of the main menu items having a dropdown menu. The problem is if I scroll the main menu the drop down menus do not follow (absolute positioning), or if I make them follow (relative) they push the main menu up.



Absolute:



enter image description here



Relative:



enter image description here



The CSS is:



.navbar 
width:100%;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;


.dropdown-content
display: none; //displayed on hover
position: absolute; //or relative
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;



Any suggestions as to what I can do to fix this?



What I am looking for is the absolute version - notice the drop down menu drops over the scroll bar, not pushing it down - but with the sub menu properly aligned.



See jsfiddle for example of absolute postioning:



https://jsfiddle.net/9hjgo1qc/7/










share|improve this question















I have a horizontal scrolling menu with some of the main menu items having a dropdown menu. The problem is if I scroll the main menu the drop down menus do not follow (absolute positioning), or if I make them follow (relative) they push the main menu up.



Absolute:



enter image description here



Relative:



enter image description here



The CSS is:



.navbar 
width:100%;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;


.dropdown-content
display: none; //displayed on hover
position: absolute; //or relative
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;



Any suggestions as to what I can do to fix this?



What I am looking for is the absolute version - notice the drop down menu drops over the scroll bar, not pushing it down - but with the sub menu properly aligned.



See jsfiddle for example of absolute postioning:



https://jsfiddle.net/9hjgo1qc/7/







html css






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 23:36

























asked Nov 9 at 21:40









RGriffiths

2,233114478




2,233114478







  • 1




    Maybe provide enough sample to actually reproduce the issue first? A couple css classes isn't exactly helpful unless you're hoping someone just writes you a menu, you know this amigo...
    – Chris W.
    Nov 9 at 21:44










  • Exactly. Provide (at least) HTML to see how did you implement those menus. The catch will be there, I guess.
    – Nemanja Glumac
    Nov 9 at 21:45










  • It's not necessarily the css that is needed here, providing your HTML should be enough. That said, the problem is likely in your HTML. Your absolute positioned submenu should be inside its corresponding parent and that parent should be position: relative
    – Chaosxmk
    Nov 9 at 21:58










  • @RGriffiths ok, this is extremely ugly and I made it in few minutes, but it serves a purpose, I guess. No positioning at all needed. Once you provide jsfiddle, I can write an official answer if you wish with more sophisticated and elaborate code :) . codepen.io/anon/pen/zMBjyP
    – Nemanja Glumac
    Nov 9 at 22:06













  • 1




    Maybe provide enough sample to actually reproduce the issue first? A couple css classes isn't exactly helpful unless you're hoping someone just writes you a menu, you know this amigo...
    – Chris W.
    Nov 9 at 21:44










  • Exactly. Provide (at least) HTML to see how did you implement those menus. The catch will be there, I guess.
    – Nemanja Glumac
    Nov 9 at 21:45










  • It's not necessarily the css that is needed here, providing your HTML should be enough. That said, the problem is likely in your HTML. Your absolute positioned submenu should be inside its corresponding parent and that parent should be position: relative
    – Chaosxmk
    Nov 9 at 21:58










  • @RGriffiths ok, this is extremely ugly and I made it in few minutes, but it serves a purpose, I guess. No positioning at all needed. Once you provide jsfiddle, I can write an official answer if you wish with more sophisticated and elaborate code :) . codepen.io/anon/pen/zMBjyP
    – Nemanja Glumac
    Nov 9 at 22:06








1




1




Maybe provide enough sample to actually reproduce the issue first? A couple css classes isn't exactly helpful unless you're hoping someone just writes you a menu, you know this amigo...
– Chris W.
Nov 9 at 21:44




Maybe provide enough sample to actually reproduce the issue first? A couple css classes isn't exactly helpful unless you're hoping someone just writes you a menu, you know this amigo...
– Chris W.
Nov 9 at 21:44












Exactly. Provide (at least) HTML to see how did you implement those menus. The catch will be there, I guess.
– Nemanja Glumac
Nov 9 at 21:45




Exactly. Provide (at least) HTML to see how did you implement those menus. The catch will be there, I guess.
– Nemanja Glumac
Nov 9 at 21:45












It's not necessarily the css that is needed here, providing your HTML should be enough. That said, the problem is likely in your HTML. Your absolute positioned submenu should be inside its corresponding parent and that parent should be position: relative
– Chaosxmk
Nov 9 at 21:58




It's not necessarily the css that is needed here, providing your HTML should be enough. That said, the problem is likely in your HTML. Your absolute positioned submenu should be inside its corresponding parent and that parent should be position: relative
– Chaosxmk
Nov 9 at 21:58












@RGriffiths ok, this is extremely ugly and I made it in few minutes, but it serves a purpose, I guess. No positioning at all needed. Once you provide jsfiddle, I can write an official answer if you wish with more sophisticated and elaborate code :) . codepen.io/anon/pen/zMBjyP
– Nemanja Glumac
Nov 9 at 22:06





@RGriffiths ok, this is extremely ugly and I made it in few minutes, but it serves a purpose, I guess. No positioning at all needed. Once you provide jsfiddle, I can write an official answer if you wish with more sophisticated and elaborate code :) . codepen.io/anon/pen/zMBjyP
– Nemanja Glumac
Nov 9 at 22:06













2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Just add vertical-align:top; on .dropdown class style. Fixes your problem.



Test it here



Update 1



Used JQuery to fix the problem.



See here



Update 2



You can achieve same thing for multiple menus with minor change in jquery method.



See here






share|improve this answer






















  • Thanks, but one thing fixed, another problem emerges. In absolute this does not fix the issue. In relative it simple reverses the problem and pushes the menu down. See fiddle.
    – RGriffiths
    Nov 9 at 23:01










  • If you can use the JQuery then it will be easier to fix it.. jsfiddle.net/nimittshah/1vybc7fz
    – Nimit Shah
    Nov 12 at 18:39










  • Again, many thanks for your efforts. This will work for one sub-menu, but not if there are more than one.
    – RGriffiths
    Nov 13 at 1:11










  • I have updated the answer with Update 2. You can also check it here
    – Nimit Shah
    Nov 13 at 18:07










  • That is fantastic - thank you for all your help with this.
    – RGriffiths
    Nov 13 at 22:16

















up vote
0
down vote













Like I already said in the comment, you don't actually need any kind of positioning to achieve this. It's just a matter of good HTML code. I have already provided a codepen example, but it was anonymus and someone had rewritten it.



You can achieve exactly what you want in just a few lines of code. I have started editing your jsfiddle, but figured I have already given you all the code needed in my codepen example :)






.navbar 
margin: 200px auto;
display: flex;
width: 800px;
overflow-x: scroll;


ul
min-width: 250px;
list-style: none;


li
display: inline-block;
text-align: center;
height: 40px;
line-height: 40px; /* quick hack to center text vertically (assuming it is just one line), but I wouldn't use it for production - it is just for this quick example */
background: beige;
margin: 0;
border: 1px solid white;


ul li:not(:first-child)
height: 0;
transition: all .3s ease-in;
visibility: hidden;
/* alternatively you can use transform and scaleY
transform: scaleY(0);
transform-origin: 50% 0; */


ul:hover li:not(:first-child)
height: 40px;
visibility: visible;
/* transform: scaleY(1); */

<div class="navbar">
<ul>
<li>M1</li>
<li>M1-1</li>
<li>M1-2</li>
</ul>
<ul>
<li>M2</li>
<li>M2-1</li>
<li>M2-2</li>
</ul>
<ul>
<li>M3</li>
<li>M3-1</li>
<li>M3-2</li>
</ul>
<ul>
<li>M4</li>
<li>M4-1</li>
<li>M4-2</li>
</ul>
<ul>
<li>M5</li>
<li>M5-1</li>
<li>M5-2</li>
</ul>
</div>





This is dummy code, but I think you can translate it to your example, easily. Let me know if you need me to explain this further.






share|improve this answer






















  • This is fine but it pushes the menu down. This is in effect the same problem reversed. Look at my fiddle again and how the "More text" doesn't move (orthe menu bar).
    – RGriffiths
    Nov 9 at 22:56










  • Well, then I don't understand what it is that you would like to achieve? You said that they either don't follow, or push the menu up. It was logical to me that you want the dropdown menu do open downwards? I'm confused. So if you'd clarify, please...
    – Nemanja Glumac
    Nov 9 at 23:00










  • I should have written "or the scroll bar". If you look at your answer when the submenu opens the scroll bar drops. This is not the effect we want on a menu - we want the submenu to open over the scroll bar. see the fiddle - it shows you. Appreciate your help.
    – RGriffiths
    Nov 9 at 23:03










  • Oh, too bad. It really wasn't clear but now I get what you mean and yeah - this doesn't help in that scenario. Good luck.
    – Nemanja Glumac
    Nov 9 at 23:08










  • Thanks for trying
    – RGriffiths
    Nov 9 at 23:33










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233589%2fcss-scrolling-menu-dropdown-menu-doesnt-scroll-properly%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Just add vertical-align:top; on .dropdown class style. Fixes your problem.



Test it here



Update 1



Used JQuery to fix the problem.



See here



Update 2



You can achieve same thing for multiple menus with minor change in jquery method.



See here






share|improve this answer






















  • Thanks, but one thing fixed, another problem emerges. In absolute this does not fix the issue. In relative it simple reverses the problem and pushes the menu down. See fiddle.
    – RGriffiths
    Nov 9 at 23:01










  • If you can use the JQuery then it will be easier to fix it.. jsfiddle.net/nimittshah/1vybc7fz
    – Nimit Shah
    Nov 12 at 18:39










  • Again, many thanks for your efforts. This will work for one sub-menu, but not if there are more than one.
    – RGriffiths
    Nov 13 at 1:11










  • I have updated the answer with Update 2. You can also check it here
    – Nimit Shah
    Nov 13 at 18:07










  • That is fantastic - thank you for all your help with this.
    – RGriffiths
    Nov 13 at 22:16














up vote
1
down vote



accepted










Just add vertical-align:top; on .dropdown class style. Fixes your problem.



Test it here



Update 1



Used JQuery to fix the problem.



See here



Update 2



You can achieve same thing for multiple menus with minor change in jquery method.



See here






share|improve this answer






















  • Thanks, but one thing fixed, another problem emerges. In absolute this does not fix the issue. In relative it simple reverses the problem and pushes the menu down. See fiddle.
    – RGriffiths
    Nov 9 at 23:01










  • If you can use the JQuery then it will be easier to fix it.. jsfiddle.net/nimittshah/1vybc7fz
    – Nimit Shah
    Nov 12 at 18:39










  • Again, many thanks for your efforts. This will work for one sub-menu, but not if there are more than one.
    – RGriffiths
    Nov 13 at 1:11










  • I have updated the answer with Update 2. You can also check it here
    – Nimit Shah
    Nov 13 at 18:07










  • That is fantastic - thank you for all your help with this.
    – RGriffiths
    Nov 13 at 22:16












up vote
1
down vote



accepted







up vote
1
down vote



accepted






Just add vertical-align:top; on .dropdown class style. Fixes your problem.



Test it here



Update 1



Used JQuery to fix the problem.



See here



Update 2



You can achieve same thing for multiple menus with minor change in jquery method.



See here






share|improve this answer














Just add vertical-align:top; on .dropdown class style. Fixes your problem.



Test it here



Update 1



Used JQuery to fix the problem.



See here



Update 2



You can achieve same thing for multiple menus with minor change in jquery method.



See here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 at 18:07

























answered Nov 9 at 22:21









Nimit Shah

1,7391310




1,7391310











  • Thanks, but one thing fixed, another problem emerges. In absolute this does not fix the issue. In relative it simple reverses the problem and pushes the menu down. See fiddle.
    – RGriffiths
    Nov 9 at 23:01










  • If you can use the JQuery then it will be easier to fix it.. jsfiddle.net/nimittshah/1vybc7fz
    – Nimit Shah
    Nov 12 at 18:39










  • Again, many thanks for your efforts. This will work for one sub-menu, but not if there are more than one.
    – RGriffiths
    Nov 13 at 1:11










  • I have updated the answer with Update 2. You can also check it here
    – Nimit Shah
    Nov 13 at 18:07










  • That is fantastic - thank you for all your help with this.
    – RGriffiths
    Nov 13 at 22:16
















  • Thanks, but one thing fixed, another problem emerges. In absolute this does not fix the issue. In relative it simple reverses the problem and pushes the menu down. See fiddle.
    – RGriffiths
    Nov 9 at 23:01










  • If you can use the JQuery then it will be easier to fix it.. jsfiddle.net/nimittshah/1vybc7fz
    – Nimit Shah
    Nov 12 at 18:39










  • Again, many thanks for your efforts. This will work for one sub-menu, but not if there are more than one.
    – RGriffiths
    Nov 13 at 1:11










  • I have updated the answer with Update 2. You can also check it here
    – Nimit Shah
    Nov 13 at 18:07










  • That is fantastic - thank you for all your help with this.
    – RGriffiths
    Nov 13 at 22:16















Thanks, but one thing fixed, another problem emerges. In absolute this does not fix the issue. In relative it simple reverses the problem and pushes the menu down. See fiddle.
– RGriffiths
Nov 9 at 23:01




Thanks, but one thing fixed, another problem emerges. In absolute this does not fix the issue. In relative it simple reverses the problem and pushes the menu down. See fiddle.
– RGriffiths
Nov 9 at 23:01












If you can use the JQuery then it will be easier to fix it.. jsfiddle.net/nimittshah/1vybc7fz
– Nimit Shah
Nov 12 at 18:39




If you can use the JQuery then it will be easier to fix it.. jsfiddle.net/nimittshah/1vybc7fz
– Nimit Shah
Nov 12 at 18:39












Again, many thanks for your efforts. This will work for one sub-menu, but not if there are more than one.
– RGriffiths
Nov 13 at 1:11




Again, many thanks for your efforts. This will work for one sub-menu, but not if there are more than one.
– RGriffiths
Nov 13 at 1:11












I have updated the answer with Update 2. You can also check it here
– Nimit Shah
Nov 13 at 18:07




I have updated the answer with Update 2. You can also check it here
– Nimit Shah
Nov 13 at 18:07












That is fantastic - thank you for all your help with this.
– RGriffiths
Nov 13 at 22:16




That is fantastic - thank you for all your help with this.
– RGriffiths
Nov 13 at 22:16












up vote
0
down vote













Like I already said in the comment, you don't actually need any kind of positioning to achieve this. It's just a matter of good HTML code. I have already provided a codepen example, but it was anonymus and someone had rewritten it.



You can achieve exactly what you want in just a few lines of code. I have started editing your jsfiddle, but figured I have already given you all the code needed in my codepen example :)






.navbar 
margin: 200px auto;
display: flex;
width: 800px;
overflow-x: scroll;


ul
min-width: 250px;
list-style: none;


li
display: inline-block;
text-align: center;
height: 40px;
line-height: 40px; /* quick hack to center text vertically (assuming it is just one line), but I wouldn't use it for production - it is just for this quick example */
background: beige;
margin: 0;
border: 1px solid white;


ul li:not(:first-child)
height: 0;
transition: all .3s ease-in;
visibility: hidden;
/* alternatively you can use transform and scaleY
transform: scaleY(0);
transform-origin: 50% 0; */


ul:hover li:not(:first-child)
height: 40px;
visibility: visible;
/* transform: scaleY(1); */

<div class="navbar">
<ul>
<li>M1</li>
<li>M1-1</li>
<li>M1-2</li>
</ul>
<ul>
<li>M2</li>
<li>M2-1</li>
<li>M2-2</li>
</ul>
<ul>
<li>M3</li>
<li>M3-1</li>
<li>M3-2</li>
</ul>
<ul>
<li>M4</li>
<li>M4-1</li>
<li>M4-2</li>
</ul>
<ul>
<li>M5</li>
<li>M5-1</li>
<li>M5-2</li>
</ul>
</div>





This is dummy code, but I think you can translate it to your example, easily. Let me know if you need me to explain this further.






share|improve this answer






















  • This is fine but it pushes the menu down. This is in effect the same problem reversed. Look at my fiddle again and how the "More text" doesn't move (orthe menu bar).
    – RGriffiths
    Nov 9 at 22:56










  • Well, then I don't understand what it is that you would like to achieve? You said that they either don't follow, or push the menu up. It was logical to me that you want the dropdown menu do open downwards? I'm confused. So if you'd clarify, please...
    – Nemanja Glumac
    Nov 9 at 23:00










  • I should have written "or the scroll bar". If you look at your answer when the submenu opens the scroll bar drops. This is not the effect we want on a menu - we want the submenu to open over the scroll bar. see the fiddle - it shows you. Appreciate your help.
    – RGriffiths
    Nov 9 at 23:03










  • Oh, too bad. It really wasn't clear but now I get what you mean and yeah - this doesn't help in that scenario. Good luck.
    – Nemanja Glumac
    Nov 9 at 23:08










  • Thanks for trying
    – RGriffiths
    Nov 9 at 23:33














up vote
0
down vote













Like I already said in the comment, you don't actually need any kind of positioning to achieve this. It's just a matter of good HTML code. I have already provided a codepen example, but it was anonymus and someone had rewritten it.



You can achieve exactly what you want in just a few lines of code. I have started editing your jsfiddle, but figured I have already given you all the code needed in my codepen example :)






.navbar 
margin: 200px auto;
display: flex;
width: 800px;
overflow-x: scroll;


ul
min-width: 250px;
list-style: none;


li
display: inline-block;
text-align: center;
height: 40px;
line-height: 40px; /* quick hack to center text vertically (assuming it is just one line), but I wouldn't use it for production - it is just for this quick example */
background: beige;
margin: 0;
border: 1px solid white;


ul li:not(:first-child)
height: 0;
transition: all .3s ease-in;
visibility: hidden;
/* alternatively you can use transform and scaleY
transform: scaleY(0);
transform-origin: 50% 0; */


ul:hover li:not(:first-child)
height: 40px;
visibility: visible;
/* transform: scaleY(1); */

<div class="navbar">
<ul>
<li>M1</li>
<li>M1-1</li>
<li>M1-2</li>
</ul>
<ul>
<li>M2</li>
<li>M2-1</li>
<li>M2-2</li>
</ul>
<ul>
<li>M3</li>
<li>M3-1</li>
<li>M3-2</li>
</ul>
<ul>
<li>M4</li>
<li>M4-1</li>
<li>M4-2</li>
</ul>
<ul>
<li>M5</li>
<li>M5-1</li>
<li>M5-2</li>
</ul>
</div>





This is dummy code, but I think you can translate it to your example, easily. Let me know if you need me to explain this further.






share|improve this answer






















  • This is fine but it pushes the menu down. This is in effect the same problem reversed. Look at my fiddle again and how the "More text" doesn't move (orthe menu bar).
    – RGriffiths
    Nov 9 at 22:56










  • Well, then I don't understand what it is that you would like to achieve? You said that they either don't follow, or push the menu up. It was logical to me that you want the dropdown menu do open downwards? I'm confused. So if you'd clarify, please...
    – Nemanja Glumac
    Nov 9 at 23:00










  • I should have written "or the scroll bar". If you look at your answer when the submenu opens the scroll bar drops. This is not the effect we want on a menu - we want the submenu to open over the scroll bar. see the fiddle - it shows you. Appreciate your help.
    – RGriffiths
    Nov 9 at 23:03










  • Oh, too bad. It really wasn't clear but now I get what you mean and yeah - this doesn't help in that scenario. Good luck.
    – Nemanja Glumac
    Nov 9 at 23:08










  • Thanks for trying
    – RGriffiths
    Nov 9 at 23:33












up vote
0
down vote










up vote
0
down vote









Like I already said in the comment, you don't actually need any kind of positioning to achieve this. It's just a matter of good HTML code. I have already provided a codepen example, but it was anonymus and someone had rewritten it.



You can achieve exactly what you want in just a few lines of code. I have started editing your jsfiddle, but figured I have already given you all the code needed in my codepen example :)






.navbar 
margin: 200px auto;
display: flex;
width: 800px;
overflow-x: scroll;


ul
min-width: 250px;
list-style: none;


li
display: inline-block;
text-align: center;
height: 40px;
line-height: 40px; /* quick hack to center text vertically (assuming it is just one line), but I wouldn't use it for production - it is just for this quick example */
background: beige;
margin: 0;
border: 1px solid white;


ul li:not(:first-child)
height: 0;
transition: all .3s ease-in;
visibility: hidden;
/* alternatively you can use transform and scaleY
transform: scaleY(0);
transform-origin: 50% 0; */


ul:hover li:not(:first-child)
height: 40px;
visibility: visible;
/* transform: scaleY(1); */

<div class="navbar">
<ul>
<li>M1</li>
<li>M1-1</li>
<li>M1-2</li>
</ul>
<ul>
<li>M2</li>
<li>M2-1</li>
<li>M2-2</li>
</ul>
<ul>
<li>M3</li>
<li>M3-1</li>
<li>M3-2</li>
</ul>
<ul>
<li>M4</li>
<li>M4-1</li>
<li>M4-2</li>
</ul>
<ul>
<li>M5</li>
<li>M5-1</li>
<li>M5-2</li>
</ul>
</div>





This is dummy code, but I think you can translate it to your example, easily. Let me know if you need me to explain this further.






share|improve this answer














Like I already said in the comment, you don't actually need any kind of positioning to achieve this. It's just a matter of good HTML code. I have already provided a codepen example, but it was anonymus and someone had rewritten it.



You can achieve exactly what you want in just a few lines of code. I have started editing your jsfiddle, but figured I have already given you all the code needed in my codepen example :)






.navbar 
margin: 200px auto;
display: flex;
width: 800px;
overflow-x: scroll;


ul
min-width: 250px;
list-style: none;


li
display: inline-block;
text-align: center;
height: 40px;
line-height: 40px; /* quick hack to center text vertically (assuming it is just one line), but I wouldn't use it for production - it is just for this quick example */
background: beige;
margin: 0;
border: 1px solid white;


ul li:not(:first-child)
height: 0;
transition: all .3s ease-in;
visibility: hidden;
/* alternatively you can use transform and scaleY
transform: scaleY(0);
transform-origin: 50% 0; */


ul:hover li:not(:first-child)
height: 40px;
visibility: visible;
/* transform: scaleY(1); */

<div class="navbar">
<ul>
<li>M1</li>
<li>M1-1</li>
<li>M1-2</li>
</ul>
<ul>
<li>M2</li>
<li>M2-1</li>
<li>M2-2</li>
</ul>
<ul>
<li>M3</li>
<li>M3-1</li>
<li>M3-2</li>
</ul>
<ul>
<li>M4</li>
<li>M4-1</li>
<li>M4-2</li>
</ul>
<ul>
<li>M5</li>
<li>M5-1</li>
<li>M5-2</li>
</ul>
</div>





This is dummy code, but I think you can translate it to your example, easily. Let me know if you need me to explain this further.






.navbar 
margin: 200px auto;
display: flex;
width: 800px;
overflow-x: scroll;


ul
min-width: 250px;
list-style: none;


li
display: inline-block;
text-align: center;
height: 40px;
line-height: 40px; /* quick hack to center text vertically (assuming it is just one line), but I wouldn't use it for production - it is just for this quick example */
background: beige;
margin: 0;
border: 1px solid white;


ul li:not(:first-child)
height: 0;
transition: all .3s ease-in;
visibility: hidden;
/* alternatively you can use transform and scaleY
transform: scaleY(0);
transform-origin: 50% 0; */


ul:hover li:not(:first-child)
height: 40px;
visibility: visible;
/* transform: scaleY(1); */

<div class="navbar">
<ul>
<li>M1</li>
<li>M1-1</li>
<li>M1-2</li>
</ul>
<ul>
<li>M2</li>
<li>M2-1</li>
<li>M2-2</li>
</ul>
<ul>
<li>M3</li>
<li>M3-1</li>
<li>M3-2</li>
</ul>
<ul>
<li>M4</li>
<li>M4-1</li>
<li>M4-2</li>
</ul>
<ul>
<li>M5</li>
<li>M5-1</li>
<li>M5-2</li>
</ul>
</div>





.navbar 
margin: 200px auto;
display: flex;
width: 800px;
overflow-x: scroll;


ul
min-width: 250px;
list-style: none;


li
display: inline-block;
text-align: center;
height: 40px;
line-height: 40px; /* quick hack to center text vertically (assuming it is just one line), but I wouldn't use it for production - it is just for this quick example */
background: beige;
margin: 0;
border: 1px solid white;


ul li:not(:first-child)
height: 0;
transition: all .3s ease-in;
visibility: hidden;
/* alternatively you can use transform and scaleY
transform: scaleY(0);
transform-origin: 50% 0; */


ul:hover li:not(:first-child)
height: 40px;
visibility: visible;
/* transform: scaleY(1); */

<div class="navbar">
<ul>
<li>M1</li>
<li>M1-1</li>
<li>M1-2</li>
</ul>
<ul>
<li>M2</li>
<li>M2-1</li>
<li>M2-2</li>
</ul>
<ul>
<li>M3</li>
<li>M3-1</li>
<li>M3-2</li>
</ul>
<ul>
<li>M4</li>
<li>M4-1</li>
<li>M4-2</li>
</ul>
<ul>
<li>M5</li>
<li>M5-1</li>
<li>M5-2</li>
</ul>
</div>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 22:54

























answered Nov 9 at 22:26









Nemanja Glumac

244212




244212











  • This is fine but it pushes the menu down. This is in effect the same problem reversed. Look at my fiddle again and how the "More text" doesn't move (orthe menu bar).
    – RGriffiths
    Nov 9 at 22:56










  • Well, then I don't understand what it is that you would like to achieve? You said that they either don't follow, or push the menu up. It was logical to me that you want the dropdown menu do open downwards? I'm confused. So if you'd clarify, please...
    – Nemanja Glumac
    Nov 9 at 23:00










  • I should have written "or the scroll bar". If you look at your answer when the submenu opens the scroll bar drops. This is not the effect we want on a menu - we want the submenu to open over the scroll bar. see the fiddle - it shows you. Appreciate your help.
    – RGriffiths
    Nov 9 at 23:03










  • Oh, too bad. It really wasn't clear but now I get what you mean and yeah - this doesn't help in that scenario. Good luck.
    – Nemanja Glumac
    Nov 9 at 23:08










  • Thanks for trying
    – RGriffiths
    Nov 9 at 23:33
















  • This is fine but it pushes the menu down. This is in effect the same problem reversed. Look at my fiddle again and how the "More text" doesn't move (orthe menu bar).
    – RGriffiths
    Nov 9 at 22:56










  • Well, then I don't understand what it is that you would like to achieve? You said that they either don't follow, or push the menu up. It was logical to me that you want the dropdown menu do open downwards? I'm confused. So if you'd clarify, please...
    – Nemanja Glumac
    Nov 9 at 23:00










  • I should have written "or the scroll bar". If you look at your answer when the submenu opens the scroll bar drops. This is not the effect we want on a menu - we want the submenu to open over the scroll bar. see the fiddle - it shows you. Appreciate your help.
    – RGriffiths
    Nov 9 at 23:03










  • Oh, too bad. It really wasn't clear but now I get what you mean and yeah - this doesn't help in that scenario. Good luck.
    – Nemanja Glumac
    Nov 9 at 23:08










  • Thanks for trying
    – RGriffiths
    Nov 9 at 23:33















This is fine but it pushes the menu down. This is in effect the same problem reversed. Look at my fiddle again and how the "More text" doesn't move (orthe menu bar).
– RGriffiths
Nov 9 at 22:56




This is fine but it pushes the menu down. This is in effect the same problem reversed. Look at my fiddle again and how the "More text" doesn't move (orthe menu bar).
– RGriffiths
Nov 9 at 22:56












Well, then I don't understand what it is that you would like to achieve? You said that they either don't follow, or push the menu up. It was logical to me that you want the dropdown menu do open downwards? I'm confused. So if you'd clarify, please...
– Nemanja Glumac
Nov 9 at 23:00




Well, then I don't understand what it is that you would like to achieve? You said that they either don't follow, or push the menu up. It was logical to me that you want the dropdown menu do open downwards? I'm confused. So if you'd clarify, please...
– Nemanja Glumac
Nov 9 at 23:00












I should have written "or the scroll bar". If you look at your answer when the submenu opens the scroll bar drops. This is not the effect we want on a menu - we want the submenu to open over the scroll bar. see the fiddle - it shows you. Appreciate your help.
– RGriffiths
Nov 9 at 23:03




I should have written "or the scroll bar". If you look at your answer when the submenu opens the scroll bar drops. This is not the effect we want on a menu - we want the submenu to open over the scroll bar. see the fiddle - it shows you. Appreciate your help.
– RGriffiths
Nov 9 at 23:03












Oh, too bad. It really wasn't clear but now I get what you mean and yeah - this doesn't help in that scenario. Good luck.
– Nemanja Glumac
Nov 9 at 23:08




Oh, too bad. It really wasn't clear but now I get what you mean and yeah - this doesn't help in that scenario. Good luck.
– Nemanja Glumac
Nov 9 at 23:08












Thanks for trying
– RGriffiths
Nov 9 at 23:33




Thanks for trying
– RGriffiths
Nov 9 at 23:33

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233589%2fcss-scrolling-menu-dropdown-menu-doesnt-scroll-properly%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo