您的位置:首頁技術文章
文章詳情頁

css - DIV 讓數字水平垂直置中?

瀏覽:100日期:2023-01-19 13:23:46

問題描述

.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>

這樣設定的時候,數字都會中間偏下,沒辦法完全中間。請問該怎麼讓他完全水平垂直置中?

css - DIV 讓數字水平垂直置中?

問題解答

回答1:

css - DIV 讓數字水平垂直置中?

.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 設為相等即可多行文字需要將文字抱在p標簽中 外層p display:table 內層p display:table-cell

回答3:

text-align:center; + line-height:容器元素高度

回答4:

既然你都設置 height 了,那就直接設置 line-height 吧

回答5:

**設置一下行高就好了 transform: translate(0,-50%) 這句 可以 刪除**

回答6:

單行的垂直居中 使用line-height 即可。

回答7:

p中單行文字垂直居中,設置line-height和height兩個屬性,且兩者值相同即可實現。

標簽: CSS
相關文章:
国产综合久久一区二区三区