CSS将文本对齐“形状”

时间:2018-05-08 13:30:02

标签: css

我一直试图改变“形状”里面文字的位置 但它总是向左推。

bala {
  display: inline-flex;
  vertical-align: middle;
    height: 22px;
    width: 22px;
    line-height: 22px;

    -moz-border-radius: 30px;
    border-radius: 30px;

    background-color: black;
    color: white;
    font-size: 14px;
}
<p> <bala>21</bala> Done <MdError color='#fcb51b' /> In Progress:{inProgress} </p>

enter image description here

2 个答案:

答案 0 :(得分:1)

添加justify-content: center;解决问题。

bala {
  display: inline-flex;
  justify-content: center;
  vertical-align: middle;
    height: 22px;
    width: 22px;
    line-height: 22px;

    -moz-border-radius: 30px;
    border-radius: 30px;

    background-color: black;
    color: white;
    font-size: 14px;
}
<p> <bala>21</bala> Done <MdError color='#fcb51b' /> In Progress:{inProgress} </p>

答案 1 :(得分:0)

尝试将display: inline-flex;更改为display: inline-block;,然后添加text-align: center;

bala {
  display: inline-block;
  vertical-align: middle;
  height: 22px;
  width: 22px;
  line-height: 22px;
  -moz-border-radius: 30px;
  border-radius: 30px;
  background-color: black;
  color: white;
  font-size: 14px;
  text-align: center;
}
<p>
  <bala>21</bala> Done
  <MdError color='#fcb51b' /> In Progress:{inProgress}
</p>