我试图让我的文字以服装宽度居中。 设置宽度或最大宽度会将线的位置恢复到左侧。我是这样做的:
我需要为每个自定义宽度,有 <h6>
和 <a>
在一行中,所有内容(包括边框)在中间。
最佳答案
您需要将 h1
的 parent 设置为 text-align:center
body {
text-align: center;
}
h1 {
background: lightgreen;
font-family: sans-serif;
width: 200px;
display: inline-block;
}
<h1>Some text</h1>
关于html - 文本对齐 :center is not doing well with width and display: inline-block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52664480/