【问题标题】:Align text inside a fixed width button在固定宽度按钮内对齐文本
【发布时间】:2019-10-16 03:59:55
【问题描述】:

我尝试将“>”文本与固定宽度的按钮对齐。我尝试使用对齐文本,但观察结果不是居中对齐。

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    .naviButton {
      height:34px;
      width:16px;
      color:grey;
      text-align:center;
      position:relative;
    }
    </style>
    </head>
    <body>

    <button class="naviButton"><</button>

    </body>
    </html>

如果我删除固定宽度,“>”将居中。

我有点怀疑这里的对齐元素实际上是“>”文本的开始位置。但是,我可以在文本中间居中吗?

任何人都知道它可以以固定宽度居中。非常感谢!

【问题讨论】:

  • 添加填充:0;

标签: html css alignment


【解决方案1】:

使用padding: 0;

.naviButton {
   height:34px;
   width:16px;
   color:grey;
   text-align:center;
   position:relative;
   padding: 0;
 }
&lt;button class="naviButton"&gt;&lt;&lt;/button&gt;

【讨论】:

    猜你喜欢
    • 2016-02-08
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多