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ù)字都會中間偏下,沒辦法完全中間。請問該怎麼讓他完全水平垂直置中?
問題解答
回答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. 如何設(shè)置一個(gè)無限循環(huán)并打破它。(Java線程)2. 網(wǎng)頁爬蟲 - 如何使用使用java抓取信息并制作一個(gè)排名系統(tǒng)?3. mysql - 在log日志中已知用戶的某一步操作,如何獲取其上一步操作?4. php對mysql提取數(shù)據(jù)那種速度更快5. shell - mysql更新錯(cuò)誤6. javascript - sublime快鍵鍵問題7. javascript - immutable配合react提升性能?8. python小白 自學(xué)看書遇到看不懂的地方9. macos - 如何徹底刪除mac自帶的apache和php10. DADB.class.php文件的代碼怎么寫

網(wǎng)公網(wǎng)安備