Home  >  Q&A  >  body text

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;
}

    <div class="unsolve">12</div>

    这样设定的时候,数字都会中间偏下,沒办法完全居中。请问该怎么样让他完全水平垂直居中?

橱窗的光橱窗的光2792 days ago1135

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 00:33:34

    DIV Center the number horizontally and vertically? -PHP Chinese website Q&A-DIV Center the numbers horizontally and vertically? -PHP Chinese website Q&A

    Let’s take a look and learn.

    reply
    0
  • 迷茫

    迷茫2017-02-27 09:31:06

    不用这么麻烦
    单行文字 
    将行高 line-height 和 height 设为相等即可
    多行文字
    需要将文字抱在p标签中 
    外层div display:table 内层p display:table-cell

    reply
    0
  • Cancelreply