css - 使用内联列表将 <ul> 元素居中

标签 css list centering

我有点不好意思问这个问题,但我正在努力将 UL 元素置于 DIV 中。 UL block 包含内联 LI。

这是本网站上的 NavMenu:http://dev.gratefulhearttherapy.org/

我已经对 UL 元素及其父 DIV#headerNav 和 DIV.custom 尝试了 text-align:center 和 margin:auto。都没有用。

<div id="headerNav">
<div class="custom">
<ul id="mega-menu-77" class="mega-menu" style="display:none;">
<li class="nav-selected nav-path-selected top-level-nav first il-1"><a class="nav-selected nav-path-selected pl-1" href="/" accesskey="H">Home</a></li>
<li class="top-level-nav il-72"><a href="/services/psychotherapy/" class="pl-72" accesskey="S">Services</a><ul class='sub_menu pid-72'><li class=" il-88"><a href="/services/psychotherapy/" class="pl-88" accesskey="P">Psychotherapy</a></li>
<li...> ... </li>
<li...> ... </li>
<li...> ... </li>
</ul>
</div>

复制CSS会很复杂,所以这里是直接文件:http://dev.gratefulhearttherapy.org/index.php/tools/css/themes/gratefulheart/typography-new2.css尽管使用 Firebug 或 Chrome Inspector 可以更好地了解它。

非常感谢您解决问题,或者可以引导我找到解决方案!

奥利维尔

最佳答案

.custom ul.mega-menu li 上,将 float: left 更改为 display: inline-block

li 将居中,这要归功于 text-align: center,您在父级 ul 上设置了它。

您还需要将 display: block 添加到 .custom ul.mega-menu li .sub li

关于css - 使用内联列表将 <ul> 元素居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8145521/

相关文章:

css - 扩展 Airflow Web UI 并添加静态 HTML 页面和 CSS

javascript - 添加 :focus to list items in dropdown menu

css - 使用 CSS 自定义 Google 图表

text - 如何在 Emacs 中将文本居中?

jquery - 将宽度超出视口(viewport)的元素居中

javascript - 注入(inject)内容大小问题

c# - 如何将一个列表分成两个可以容纳奇数个计数的列表?

python - 从python中的字符串中获取特定的子字符串

java - 如何在java中创建动态二维矩阵?

html - 居中多div