居中
    带有内联列表的元素

发布于 2024-12-15 15:22:21 字数 1337 浏览 4 评论 0原文

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

这是该网站上的导航菜单: http://dev.gratefulhearttherapy.org/

我尝试过文本- UL 元素及其父级 DIV#headerNav 和 DIV.custom 的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 来感知它。

非常感谢您找出答案或引导我找到解决方案!

奥利维尔

I'm a bit embarrassed to ask about this, but I'm struggling with centering a UL element inside a DIV. The UL block contains inline LIs.

This is the NavMenu on this website: http://dev.gratefulhearttherapy.org/

I've tried text-align:center and margin:auto to both the UL element and its parent DIV#headerNav and DIV.custom. None worked.

<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>

It would be complicated to copy the CSS, so here is the direct file: http://dev.gratefulhearttherapy.org/index.php/tools/css/themes/gratefulheart/typography-new2.css though you'd have a better sense of it using Firebug or Chrome Inspector.

Thanks a lot for you figure it out or can lead me to the solution!!

Olivier

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二货你真萌 2024-12-22 15:22:21

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

然后,由于父 ul 上的 text-align: centerli 将居中。

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

On .custom ul.mega-menu li, change float: left to display: inline-block.

The lis will then be centered, thanks to text-align: center which you have on the parent ul.

You'll also need to add display: block to .custom ul.mega-menu li .sub li.

孤寂小茶 2024-12-22 15:22:21

如果您想让块元素居中,请尝试以下操作:

width:980px;
margin:0 auto;

980px 可以更改为任何值。

另外,不要忘记清除浮动(在 Google 上查找“clearfix”)。

If you want to center a block element, try this:

width:980px;
margin:0 auto;

980px can be changed to any value.

Also, don't forget to clear the float (look for "clearfix" on Google).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文