可变宽度父级下的中心子菜单

时间:2014-09-29 02:32:16

标签: css center

抱歉,如果以前曾经问过这个问题,我已经看过并试过了几个选项,但我似乎无法让它发挥作用。我想把我的子菜单放在中心位置。每个父项都有可变宽度,子菜单项也有可变宽度。这是我的代码:

.menu-wrap ul li{margin:0;padding:0;display:inline-block}
.menu-wrap ul li>a{font-size:16px;color:rgba(0,0,0,.6);display:block}
.menu-wrap ul li>ul{position:absolute;float:left;left:0;right:auto;top:90px;width:auto;padding:10px 0;background:#fff;opacity:0;border-top:solid 1px rgba(245,130,32,1)}
.menu-wrap ul li.parent:hover>ul{opacity:1}


<ul class="nav menu">
  <li class="item-101"><a href="/">Home</a></li>
  <li class="item-129 parent"><a href="/about/about-us.html">About</a>
    <ul class="nav-child">
      <li class="item-148"><a href="/about/about-us.html">About Us</a></li>
      <li class="item-116"><a href="/about/testimonials.html">Testimonials</a></li>
    </ul>
  </li>
  <li class="item-114 parent"><a href="/services/services-page-example.html">Services</a>
    <ul class="nav-child">
      <li class="item-122"><a href="/services/services-page-example.html">Services Page Example</a></li>
      <li class="item-123"><a href="/services/services-page-example-2.html">Services Page Example 2</a></li>
      <li class="item-124"><a href="/services/services-page-example-3.html">Services Page Example 3</a></li>
    </ul>
  </li>
  <li class="item-154"><a href="/case-studies.html">Case Studies</a></li>
  <li class="item-115"><a href="/gallery.html">Gallery</a></li>
  <li class="item-149"><a href="/frequently-asked-questions.html">FAQ's</a></li>
  <li class="item-117"><a href="/contact.html">Contact</a></li>
</ul>

目前它只是左对齐。

1 个答案:

答案 0 :(得分:2)

我最近看到了这个指南并发现它很有帮助。

http://css-tricks.com/centering-css-complete-guide/