【问题标题】:Html: Set font-size equal to input heightHtml:设置字体大小等于输入高度
【发布时间】:2017-02-25 11:08:48
【问题描述】:

我需要将font-size 调整到input 的高度。 Input 看起来像这样:

<input type="text" id="inputt" name="test" value="ddpp" style="height:100px; width:200px; font-size:100px; line-height:100px; font-family: 'Times New Roman'">

如您所见,heightfont-sizeline-height 属性等于 100px。当我alert() 这些属性由jquery 在页面加载后所有values 等于100px。但是input 中的文本不适合input height。 我也尝试使用span

<span id="spann1" style="height:100px;font-size: 100px;border: 1px solid red;font-family: 'Times New Roman'">ddpp</span>

因此,spanheight 已更改为 113px,line-height 变为 142px。为什么?这是否意味着font-size: 100px 在现实中不是100px。那么它是如何工作的呢?

【问题讨论】:

    标签: html input height font-size


    【解决方案1】:

    您可以更改显示属性。 display 属性指定是否/如何显示元素。 每个 HTML 元素都有一个默认显示值,具体取决于它是什么类型的元素。大多数元素的默认显示值是块或内联。

    css_display_visibility

    span 有默认的 inline 值,你可以将 display 改为 inline-block 。

    内联元素:

    respect left & right margins and padding, but not top & bottom
    cannot have a width and height set
    allow other elements to sit to their left and right.
    

    行内块元素:

    allow other elements to sit to their left and right
    respect top & bottom margins and padding
    respect height and width
    

    CSS display: inline vs inline-block

    祝你好运

    【讨论】:

    • 我尝试将display:inline 设置为input。但什么都没有改变。
    • 设置显示:内联块而不是内联
    • 不工作。但无论如何input 默认有一个inline-block
    • 字体大小取决于 font-family 。更改字体系列并检查它。您还可以更改垂直对齐文本的填充
    猜你喜欢
    • 2012-10-11
    • 1970-01-01
    • 2015-06-11
    • 2012-08-23
    • 2018-11-04
    • 2011-11-26
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多