css - DIV 讓數字水平垂直置中?
问题描述
.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>
這樣設定的時候,數字都會中間偏下,沒辦法完全中間。請問該怎麼讓他完全水平垂直置中?
问题解答
回答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 设为相等即可多行文字需要将文字抱在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两个属性,且两者值相同即可实现。
相关文章:
1. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?2. docker容器呢SSH为什么连不通呢?3. css - chrome浏览器input记录上次cookie信息后,有个黄色背景~如何去除!4. docker网络端口映射,没有方便点的操作方法么?5. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?6. docker api 开发的端口怎么获取?7. docker绑定了nginx端口 外部访问不到8. android - 哪位大神知道java后台的api接口的对象传到前端后输入日期报错,是什么情况?求大神指点9. docker - 如何修改运行中容器的配置10. javascript - jquery hide()方法无效

网公网安备