css - DIV 讓數(shù)字水平垂直置中?
問題描述
.unsolve{ position: absolute; right: 10px; top:50%; transform: translate(0,-50%); z-index: 1; font-size: 13px; background-color: red; border-radius: 50%; color:#fff; width: 15px; height: 15px; padding: 5px; text-align: center;}
<p class='unsolve'>12</p>
這樣設(shè)定的時(shí)候,數(shù)字都會(huì)中間偏下,沒辦法完全中間。請問該怎麼讓他完全水平垂直置中?
問題解答
回答1:.unsolve {position: absolute;right: 10px;top:0;bottom: 0;margin:auto;z-index: 1;font-size: 13px;background-color: red;border-radius: 50%;color:#fff;width: 15px;height: 15px;line-height: 15px;padding:5px;text-align: center; }回答2:
不用這么麻煩單行文字 將行高 line-height 和 height 設(shè)為相等即可多行文字需要將文字抱在p標(biāo)簽中 外層p display:table 內(nèi)層p display:table-cell
回答3:text-align:center; + line-height:容器元素高度
回答4:既然你都設(shè)置 height 了,那就直接設(shè)置 line-height 吧
回答5:**設(shè)置一下行高就好了 transform: translate(0,-50%) 這句 可以 刪除**
回答6:單行的垂直居中 使用line-height 即可。
回答7:p中單行文字垂直居中,設(shè)置line-height和height兩個(gè)屬性,且兩者值相同即可實(shí)現(xiàn)。
相關(guān)文章:
1. angular.js - 可以通過vue或者angular雙向數(shù)據(jù)綁定iframe元素嗎?2. javascript - h5微信中怎么禁止橫屏3. index.php錯(cuò)誤,求指點(diǎn)4. angular.js - angularjs 百度統(tǒng)計(jì)怎么統(tǒng)計(jì)5. node.js - vue-cli無法創(chuàng)建項(xiàng)目。6. css3選擇器nth-of-type的問題7. css3 - 這種情景怎么解釋?display:flex 遭遇 white-space: nowrap;8. PHP單例模式9. objective-c - 微信支付的問題10. Html 入門教程視頻無法播放
