i was trying to work on html,css and i got a problem. i am using display: inline-block so that my list items cover all the width of the header. but instead of covering whole width it just floats to the left. here is a demo of html/css on jsfiddle, http://jsfiddle.net/oso6x7cd/
html
<nav id="globalheader" class="globalheader gh-selected-tab-iphone" role="navigation" aria-label="Global Navigation" data-hires="false" data-analytics-region="global nav" lang="en-US">
<div id="gh-content" class="gh-content">
<div class="gh-nav">
<div class="gh-nav-view">
<ul class="gh-nav-list">
<li class="gh-tab gh-tab-apple"><a class="gh-tab-link" href="/"><span class="gh-tab-inner"><span class="gh-text-replace">Apple</span></span></a></li>
<li class="gh-tab gh-tab-store"><a class="gh-tab-link" href="http://store.apple.com/us"><span class="gh-tab-inner"><span class="gh-text-replace">Store</span></span></a></li>
<li class="gh-tab gh-tab-mac"><a class="gh-tab-link" href="/mac/"><span class="gh-tab-inner"><span class="gh-text-replace">Mac</span></span></a></li>
<li class="gh-tab gh-tab-iphone"><a class="gh-tab-link" href="/iphone/"><span class="gh-tab-inner"><span class="gh-text-replace">iPhone</span></span></a></li>
<li class="gh-tab gh-tab-watch"><a class="gh-tab-link" href="/watch/"><span class="gh-tab-inner"><span class="gh-text-replace">Watch</span></span></a></li>
<li class="gh-tab gh-tab-ipad"><a class="gh-tab-link" href="/ipad/"><span class="gh-tab-inner"><span class="gh-text-replace">iPad</span></span></a></li>
<li class="gh-tab gh-tab-ipod"><a class="gh-tab-link" href="/ipod/"><span class="gh-tab-inner"><span class="gh-text-replace">iPod</span></span></a></li>
<li class="gh-tab gh-tab-itunes"><a class="gh-tab-link" href="/itunes/"><span class="gh-tab-inner"><span class="gh-text-replace">iTunes</span></span></a></li>
<li class="gh-tab gh-tab-support"><a class="gh-tab-link" href="/support/"><span class="gh-tab-inner"><span class="gh-text-replace">Support</span></span></a></li>
</ul>
</div>
</div><!--/gh-nav-->
</div>
</nav>
thanks
In fact inline-block is working fine. That's the normal behavior for inline-block.
Setting an element to display:inline-block;
does not make it fill it's container's width.
Setting display:table; width:100%;
display:table; width:100%;
to the ul
element and display:table-cell;
to the li
elements seems to do the trick and is relatively simple.
Updated fiddle: http://jsfiddle.net/oso6x7cd/1/
See an updated fiddle with a minimal working example along with media queries to change the padding of the menuitems as the browser window gets smaller:
http://jsfiddle.net/oso6x7cd/2/
Another update to make the nav-bar narrower according to the screen size: http://jsfiddle.net/oso6x7cd/3/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.