久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在指定容器中均勻且完全地拉伸固定數量的

How to stretch a fixed number of horizontal navigation items evenly and fully across a specified container(如何在指定容器中均勻且完全地拉伸固定數量的水平導航項)
本文介紹了如何在指定容器中均勻且完全地拉伸固定數量的水平導航項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想在一個 900 像素的容器上均勻地拉伸 6 個導航項,并且在它們之間留有均勻的空白空間.比如……

I'd like to stretch 6 nav items evenly across a 900px container, with an even amount of white space between. For instance...

---| 900px Container |---

---| HOME    ABOUT    BASIC SERVICES    SPECIALTY SERVICES    OUR STAFF    CONTACT US |---

目前,我能找到的最佳方法如下:

Currently, the best method I can find to do this is the following:

nav ul {
  width: 900px; 
  margin: 0 auto;
}

nav li {
  line-height: 87px;
  float: left;
  text-align: center;
  width: 150px;
}

這個問題有兩個方面.首先,它并沒有真正證明它的合理性,而是將 li 標簽均勻地分布在整個 ul 標簽中.在較小的菜單項(例如HOME"或ABOUT")和較大的菜單項(例如BASIC SERVICES")之間創建不均勻的空白區域.

The PROBLEM with this is two fold. First of all, it doesn't truly justify it, but rather spreads the li tags evenly throughout the ul tag.. creating uneven white-space between smaller menu items like "HOME" or "ABOUT" and larger ones like "BASIC SERVICES".

第二個問題是,如果導航項目大于 150 像素,則布局會中斷,專業服務就是這樣 - 即使整個導航有足夠的空間.

The second problem is that the layout breaks if a nav item is larger than 150px, which SPECIALTY SERVICES is - even though there is more than enough space for the whole nav.

誰能幫我解決這個問題?我一直在網上搜索解決方案,但它們似乎都不夠用.僅在可能的情況下使用 CSS/HTML...

Can anyone solve this for me? I've been scouring the web for solutions, and they all seem to come up short. CSS / HTML only if possible...

謝謝!

更新(2013 年 7 月 29 日):使用 table-cell 是實現此布局的最佳現代方式.請參閱下面菲利克斯的回答.table cell 屬性目前適用于 94% 的瀏覽器.您必須對 IE7 及以下版本做一些事情,否則應該沒問題.

UPDATE (7/29/13): Using table-cell is the best modern way to implement this layout. See felix's answer below. The table cell property works on 94% of browsers currently. You'll have to do something about IE7 and below, but otherwise should be ok.

更新(2013 年 7 月 30 日):不幸的是,如果您將此布局與媒體查詢結合使用,則會有一個 webkit 錯誤會影響這一點.現在,您必須避免更改顯示"屬性.查看 Webkit 錯誤.

UPDATE (7/30/13): Unfortunately, there is a webkit bug that impacts this if you're combining this layout with Media Queries. For now you'll have to avoid changing the 'display' property. See Webkit Bug.

更新(2014 年 7 月 25 日):下面有一個更好的解決方案,現在涉及 text-align: justify.使用它更簡單,您將避免 Webkit 錯誤.

UPDATE (7/25/14): There is a better solution to this below now involving text-align: justify. Using this is simpler and you'll avoid the Webkit bug.

推薦答案

在容器上使用 text-align:justify ,這樣無論列表中有多少元素它都可以工作(您不必計算每個列表項的 % 寬度

Use text-align:justify on the container, this way it will work no matter how many elements you have in your list (you don't have to work out % widths for each list item

    #nav {
        text-align: justify;
        min-width: 500px;
    }
    #nav:after {
        content: '';
        display: inline-block;
        width: 100%;
    }
    #nav li {
        display: inline-block;
    }

<ul id="nav">
    <li><a href="#">HOME</a></li>
    <li><a href="#">ABOUT</a></li>
    <li><a href="#">BASIC SERVICES</a></li>
    <li><a href="#">OUR STAFF</a></li>
    <li><a href="#">CONTACT US</a></li>
</ul>

FIDDLE

這篇關于如何在指定容器中均勻且完全地拉伸固定數量的水平導航項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to check for duplicate CSS rules?(如何檢查重復的 CSS 規則?)
Remove duplicate CSS declarations across multiple files(刪除多個文件中的重復 CSS 聲明)
How can I duplicate a div onclick event?(如何復制 div onclick 事件?)
opening html from google drive(從谷歌驅動器打開 html)
How to embed videos from Google drive to webpage?(如何將視頻從 Google 驅動器嵌入到網頁?)
How to view Google drive pdf link in iframe(如何在 iframe 中查看 Google Drive pdf 鏈接)
主站蜘蛛池模板: 日本五月婷婷 | 男女羞羞视频大全 | 国产高清不卡 | 91精品国产99久久 | 日韩电影中文字幕在线观看 | 亚洲精品国产第一综合99久久 | 91精品国产欧美一区二区成人 | 韩国精品在线 | 国产1区2区 | 91高清在线观看 | 麻豆精品久久 | 91久久国产综合久久 | 亚洲va国产日韩欧美精品色婷婷 | 一级免费看 | 欧美在线观看黄色 | 99热这里有精品 | 翔田千里一区二区 | 中文字幕在线中文 | 国产精品久久久久久久久久久新郎 | 国产一区二区三区久久 | 日韩精品一区二区三区 | 亚洲一区二区三区四区五区中文 | 亚洲欧美日韩精品久久亚洲区 | 天堂中文在线播放 | 国产精品99久久久久久www | 免费视频一区 | 日韩成人精品一区二区三区 | 亚洲欧美日韩国产综合 | 日韩图区| 国产精品久久久久久久久久久免费看 | av色噜噜| 国产一区二区在线免费播放 | 国产a爽一区二区久久久 | 日韩一级黄色片 | 中文在线一区二区 | 久久精品视频免费观看 | 日韩中文在线视频 | 在线观看日韩 | 久久久国产一区二区三区 | 亚洲网视频 | 国产激情一区二区三区 |