html - 如何在没有 block 级父项的情况下将文本居中放置在 anchor 内?

标签 html css

我有一组 anchor 标记,看起来像几个盒子,中间有文本。我想要的是将其中的所有文本在宽度和高度上完美居中。我可以用 display: inline-flex; 完成高度部分align-items: center;,但我无法将文本设置为水平居中。这是这些 anchor 的 HTML 及其样式:

<a class="tt-button" style="background: #808080; width: 100%; height: 100px; margin-bottom: 10px; display: inline-flex; align-items: center;" href="#">Reconhecimento</a>

我想要的只是对它们产生 text-align: center 效果。有帮助吗?

<a class="tt-button" style="background: #808080; width: 100%; height: 100px; margin-bottom: 10px; display: inline-flex; align-items: center;" href="#">Reconhecimento</a>
<a class="tt-button" style="background: #808080; width: 100%; height: 100px; margin-bottom: 10px; display: inline-flex; align-items: center;" href="#">Neurociência</a>
<a class="tt-button" style="background: #808080; width: 100%; height: 100px; margin-bottom: 10px; display: inline-flex; align-items: center;" href="#">Envolvimento Emocional</a>

最佳答案

尝试justify-content: center;,像这样:

.tt-button {
  background: #808080; 
  width: 100%; 
  height: 100px; 
  margin-bottom: 10px; 
  display: inline-flex; 
  align-items: center;
  justify-content: center;
}
<a class="tt-button" href="#">Reconhecimento</a>
<a class="tt-button" href="#">Neurociência</a>
<a class="tt-button" href="#">Envolvimento Emocional</a>

关于html - 如何在没有 block 级父项的情况下将文本居中放置在 anchor 内?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47601569/

相关文章:

javascript - html 表单上不需要的自动填充

javascript - jQuery 无法在克隆后删除部分

css - 悬停时div和文本一起改变

html - 将水平导航更改为垂直

html - 为 html 动态页面设置固定的页眉和页脚

html - CSS 规则如何覆盖另一个 CSS 规则?

jquery - 如何在低分辨率下去除bootstrap dropdown的slidedown效果

html - Bootstrap 水平对齐嵌套 Accordion

css - SASS代码问题

java - 如何在 jsp 文件中编写的 servlet 代码中应用 css 文件?