css3 - css flex 的問題
問題描述
如圖,移動端導(dǎo)航用了flex均勻分布。但是視覺上不對。因?yàn)樽謹(jǐn)?shù)不相同。導(dǎo)致間隔不整齊。現(xiàn)在想調(diào)整css 能讓字的間隔均勻分布。同時滿足
移動端同行100%
注意下面紅線
問題解答
回答1:如果只是改變css,我的認(rèn)知中好像并沒有適合你目前這種文字間距均勻的方法;不過可以通過一些樣式調(diào)整達(dá)到視覺上的舒適,如下圖:
添加一個淺色的背景;
給每個內(nèi)容之間加1像素間隔符…
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Super8_share</title> <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'> <meta name='apple-mobile-web-app-capable' content='yes'> <meta name='format-detection' content='telephone=no'> <meta content='telephone=no' name='format-detection'> <style> .list {display: flex;flex-flow: row nowrap;height: 50px; } .item {width: 20%;line-height: 50px;text-align: center;border-right: 1px solid #fff;background-color: #efefef;border-bottom: 2px solid #f00;overflow: hidden; } .item:last-child{border-right: none;} </style></head><body> <p class='list'><p name='item'>中 國</p><p name='item'>美 國</p><p name='item'>加拿大</p><p name='item'>澳大利亞</p><p name='item'>新西蘭</p> </p></body></html>
另外,還有下面這種兩邊間隔相同的方式:
只需改變一句代碼即可
flex-grow:1; // 替換 width: 20%;回答2:
美?????國 //用
overflow: hidden 隱藏超出的文字。
利用letter-spacing來解決!letter-spacing 屬性增加或減少字符間的空白(字符間距)。
類似于下面的效果://
CSS樣式:<style type='text/css'>.hotsearch dd{float: left;line-height: 24px;margin-right: 30px;overflow: hidden;text-align: center;width: 4em; /這個值是看最長能顯示幾個文字,如x,則為x em/}.hotsearch dd a{display:block;}.w2{letter-spacing:2em; /如果需要y個字兩端對齊,則為(x-y)/(y-1),這里是(4-2)/(2-1)=2em /...
回答3:貌似css還沒有這么強(qiáng)大的功能,而且每一個元素的字?jǐn)?shù)不一樣,計算出來的間距也會不一致。題主也可以試一試兩端對齊這個方式
.nav{ display:flex; width:100%; height:50px; line-height: 50px; border-bottom:1px solid #ccc; font-size: 12px; text-align: center;}a{ display:block; padding:0 10px; box-sizing: border-box; flex:1; width:1%; text-align:justify; color:#000; }a:after{ overflow:hidden; display: inline-block; height:0; content:'200B';//利用偽元素來產(chǎn)生一個換行符,不然text-align:justify;屬性不會生效 width: 100%;}.cur{ position: relative; color:#e22828;}.cur:before{ width: 100%; height:1px; content:''; position: absolute; left:0; bottom:-1px; border-bottom:1px solid #e22828; z-index: 100;}
有三個以上字體的分配的比較均勻
根據(jù)字?jǐn)?shù)設(shè)置相應(yīng)的flex-grow
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title></title> <style> .list {display: flex;flex-flow: row nowrap;height: 50px;background-color: #aaa; } .item {line-height: 50px;text-align: center;border: 1px solid #8cb;background-color: #ccc; } .item:nth-child(1) {flex-grow: 2; } .item:nth-child(2) {flex-grow: 2; } .item:nth-child(3) {flex-grow: 3; } .item:nth-child(4) {flex-grow: 4; } .item:nth-child(5) {flex-grow: 3; } </style></head><body> <p class='list'><p class='item'>中國</p><p class='item'>中國</p><p class='item'>大中國</p><p class='item'>大大中國</p><p class='item'>大中國</p> </p></body></html>
相關(guān)文章:
1. Python從URL中提取域名2. php傳對應(yīng)的id值為什么傳不了啊有木有大神會的看我下方截圖3. python - scrapy url去重4. python - Flask寫的注冊頁面,當(dāng)注冊時,如果填寫數(shù)據(jù)庫里有的相同數(shù)據(jù),就報錯5. 關(guān)于mysql聯(lián)合查詢一對多的顯示結(jié)果問題6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. 數(shù)據(jù)庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實(shí)在是找不到哪里的問題了。8. python - oslo_config9. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)10. 小白學(xué)python的問題 關(guān)于%d和%s的區(qū)別
