How To Center A CSS Drop Down Menu [closed]

[亡魂溺海] 提交于 2019-11-30 21:06:58

replace this css with what you have for #cssmenu > ul > li:

#cssmenu > ul > li {

    display:inline-block;

    margin-left: 15px;       /* This is when the drop down box appears */

    position: relative;

}

and add this to your css codes:

 #cssmenu > ul {
        text-align:center;
 }

here it is: http://jsfiddle.net/y4vDC/10/

You need your li elements to be inline, and then use text-align on the parent element to center them:

#cssmenu ul {
  text-align:center;
}
#cssmenu ul li {
  display: inline;
}

In order that they stay as inline, you need to delete the float from the list elements.

http://jsfiddle.net/y4vDC/13/

you have at least 2 easy options:

  1. set ul as display:table and margin:auto; http://jsfiddle.net/y4vDC/11/
  2. set ul as display:inline-block and text-align:center on parent http://jsfiddle.net/y4vDC/12/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!