Good afternoon. I would like to know how to center my sub menu for the main menu. The sub menu records are dynamic, so I can not give a margin-left: -px because I do not know the size that will be my sub-menu ...
Here is an example code for 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>