【问题标题】:Changing Font in input field with underline under each character更改输入字段中的字体,每个字符下都有下划线
【发布时间】:2023-03-23 20:15:01
【问题描述】:

我想在 Django 中创建一个完整的文本。间隙应显示丢失了多少个字母。 例如: 这是一个例子。我会 sh_ _ 你是我的我_ _。

我在codepen 上发现了一些有用的 css-sn-p。我尝试使用它并使用字母而不是数字并将字体更改为 Segoe UI。我遇到的问题是,当我使用 Segoe UI 时,下划线不再与字母同步。我要如何更改配置才能再次适应?

我的 SCSS 代码:

$char-w: 1ch;
$gap: .5*$char-w;
$n-char: 7;
$in-w: $n-char*($char-w + $gap);

input {
    display: block;
    margin: 2em auto;
    border: none;
    padding: 0;
    width: $in-w;
    background: repeating-linear-gradient(90deg, 
        dimgrey 0, dimgrey $char-w, 
        transparent 0, transparent $char-w + $gap) 
        0 100%/ #{$in-w - $gap} 2px no-repeat;
    font: 5ch Segoe UI; /*That's the attribute i changed*/
    letter-spacing: $gap;

    &:focus {
        outline: none;
        color: dodgerblue;
    }
}

我的 HTML 代码:

<input maxlength='7' value=''/>

【问题讨论】:

    标签: css django html sass


    【解决方案1】:

    发生这种情况的原因是您使用的字体不是monospaced(字母有单独的宽度)。如果您将字体更改为font-family: monospace;,它将起作用。

    这是一个使用 Ubuntu 的示例:

    @import url("https://fonts.googleapis.com/css?family=Ubuntu|Ubuntu+Mono");
    body {
      font: 1.2rem 'Ubuntu', sans-serif;
    }
    
    input {
      display: inline-block;
      margin: 1.2rem auto;
      border: none;
      padding: 0;
      width: 10.5ch;
      background: repeating-linear-gradient(90deg, dimgrey 0, dimgrey 1ch, transparent 0, transparent 1.5ch) 0 100%/ 10ch 2px no-repeat;
      font: 1.2rem 'Ubuntu Mono', monospace;
      letter-spacing: 0.5ch;
    }
    input:focus {
      outline: none;
      color: dodgerblue;
    }
    Lorem ipsum &lt;input maxlength='7' value=''/&gt; dolor sit amet

    【讨论】:

    • 谢谢你,为我工作。但似乎 Segoe 没有等宽字体。我说的对吗?
    猜你喜欢
    • 1970-01-01
    • 2021-05-11
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 2019-11-10
    相关资源
    最近更新 更多