代码之家  ›  专栏  ›  技术社区  ›  Marcus.Aurelianus

在固定宽度按钮内对齐文本

  •  0
  • Marcus.Aurelianus  · 技术社区  · 6 年前

    我试图将“>”文本与固定宽度的按钮对齐。我试过对齐文本,但从观察结果看它不是居中对齐的。

        <!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>

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

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

    任何人都知道它能以固定宽度居中吗?非常感谢!

    1 回复  |  直到 6 年前
        1
  •  1
  •   Casper    6 年前

    使用 padding: 0;

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