0
Good afternoon. I would like to know how to center my sub menu regarding the main menu. The sub menu entries are dynamic, so I can’t give a margin-left : -px because I don’t know how long my sub-menu will be...
follows an example code of my problem :
ul, li {
margin : 0;
padding : 0;
}
#menu {
width : 100%;
}
#menu li {
margin : 0;
list-style: none;
}
#menu > li {
display : inline-block;
border : 1px solid #000000;
cursor : pointer;
}
#menu > li:hover ul {
display : block;
}
#menu li ul {
display : none;
position : absolute;
background-color : #000000;
color : #FFFFFF;
}
#menu li ul li:hover {
background-color : #d2d2d2;
}
<ul id="menu">
<li>Menu 1</li>
<li>
Menu 2
<ul>
<li>Sub menu 1</li>
<li>Sub menu 2</li>
<li>Um subMenu que é mais longo</li>
</ul>
</li>
<li>Menu 3</li>
</ul>
as written in the title and in the statement, my problem is in the sub menu and not centering the menu itself... The centering and menu sub for the menu...
– Douglas Bernardino
I must have been rushed to read it. I redid the answer, Douglas. See if it helps you.
– juniorgarcia
Certinho.. I thought to only use css, but apparently it will be necessary to use javascript.... Thanks for the attention, Hug..
– Douglas Bernardino
I just made a change so he can do it on every submenus on the screen...
– Douglas Bernardino