我有this div其中包含一个正方形内的一些文本。我希望里面的文字显示在它的中间 - 似乎我的文字的 底部 在中间,而我希望我的文字的中间在中间。
我的CSS是:
.touch {
border-radius: 3px;
background: #eee4da;
text-align: center;
font-weight: bold;
/*z-index: 10;*/
font-size: 30px;
width: 60px;
height: 60px;
display: inline-block;
cursor: pointer;
justify-content: center;
align-items: center;
/*vertical-align: middle;*/
}
最佳答案
您应该删除 height
并向元素添加 padding
。示例 here .
CSS:
.touch {
border-radius: 3px;
background: #eee4da;
text-align: center;
font-weight: bold;
font-size: 30px;
width: 50px;
cursor: pointer;
align-items: center;
padding: 10px;
}
.grid-row {
margin-bottom: 10px;
}
如您所见here 居中作用于多个元素.
关于html - 在div中垂直居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26724020/