【问题标题】:how to Change font size, Without changing the size of button in CSS如何更改字体大小,而不更改 CSS 中按钮的大小
【发布时间】:2017-11-24 18:53:15
【问题描述】:

在下面的代码中,我只想更改内部字体大小而不是按钮大小。

<html>
    <head>
        <style>
            .sm {
                font-size:x-small;
            }
        </style>
    </head>
    <body>
        <button class="sm">submit</button>
    </body>
</html>

【问题讨论】:

  • 你必须指定高度
  • 如果您希望文本保持居中,请将按钮填充减少 1/2 像素值,增加文本。

标签: html css font-size


【解决方案1】:

把你的风格改成这个

.sm
{
  font-size:20px;
  height:30px;
  width: 120px;
}

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    只需将您的文本包装在 div 标签中并在 css 中编辑它

    【讨论】:

      【解决方案3】:

      要在不更改按钮大小的情况下更改文本大小,您需要固定按钮的大小。这可以在 CSS 中使用 heightwidth 来完成。这样您就可以更改 font-size 而不会影响按钮大小。

      看看我下面的代码。如您所见,更改了heightwidth,按钮现在是固定大小的。文本比按钮大就证明了这一点。

      CSS

      button {
        font-size: 30px;
        height: 60px;
        width: 60px;
      }
      

      HTML

      <button>
      Hello
      </button>
      

      【讨论】:

        【解决方案4】:

        你也可以使用对我来说效果很好的 span 标签。

         <button><span style="font-size:10px;">ClickMe</span></button>
        

        【讨论】:

          猜你喜欢
          • 2017-08-07
          • 1970-01-01
          • 1970-01-01
          • 2011-02-24
          • 1970-01-01
          • 1970-01-01
          • 2021-07-18
          • 1970-01-01
          • 2019-05-02
          相关资源
          最近更新 更多