问题
sorry if this has been asked before, I've looked and have tried several options but I can't seem to get this to work. I want to center my submenu. Each parent item has variable widths, and the submenu items also have variable widths.. This is my code:
.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>
Currently it's just left aligned.
回答1:
I came across this guide recently and found it helpful.
http://css-tricks.com/centering-css-complete-guide/
来源:https://stackoverflow.com/questions/26091760/center-submenu-under-variable-width-parent