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:
Relative:
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
add a comment |
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:
Relative:
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
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
add a comment |
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:
Relative:
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
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:
Relative:
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
html css
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
add a comment |
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
add a comment |
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
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
add a comment |
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.
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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>
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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