html - 文本对齐 :center is not doing well with width and display: inline-block

标签 html css width inline text-align

我试图让我的文字以服装宽度居中。 设置宽度或最大宽度会将线的位置恢复到左侧。我是这样做的:

HTML file

CSS file

Result

我需要为每个自定义宽度,有 <h6><a>在一行中,所有内容(包括边框)在中间。

最佳答案

您需要将 h1parent 设置为 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/

相关文章:

javascript - 为什么 document.getElementById 在这里返回 null?

javascript - 如何选择#document 中的元素来更改 CSS?

javascript - Webkit 中的同步重绘/等待 DOM 更新?

CSS宽度问题child parent

php - 使用 PHP、JS、CSS 和 HTML 创建类似跳棋的实时 Web 应用程序?

javascript - javascript 中的动态复选框列表 - 不起作用

css - Flexbox 中的第一个 child 全宽

java - 我正在尝试用java创建一个三角形

css - 页面溢出到正文右侧

javascript - 我怎样才能得到这个标签来转到不包括以下代码的链接