代码之家  ›  专栏  ›  技术社区  ›  jcubic

代码笔上的ASCII艺术并不总是显示下划线

  •  1
  • jcubic  · 技术社区  · 7 年前

    enter image description here

    Codepen使用iframe,我已经在本地进行了测试,iframe看起来还可以。Codpen在FireFox中看起来也不错。如果打开Codpen调试模式,它看起来也正常。

    从开发人员工具复制的CSS(除了 ::selection

    .terminal .terminal-output div span {
        display: inline-block;
    }
    .terminal .terminal-output > div:not(.raw) div {
        white-space: nowrap;
    }
    .terminal .terminal-output > div > div {
        min-height: calc(var(--size, 1) * 14px);
    }
    .terminal, .terminal-output > :not(.raw) span,
    .terminal-output > :not(.raw) a,
    .terminal-output > :not(.raw) div,
     .cmd, .cmd span, .cmd div {
        font-size: calc(var(--size, 1) * 12px);
        line-height: calc(var(--size, 1) * 14px);
    }
    .terminal, .terminal-output > :not(.raw) span,
    .terminal-output > :not(.raw) a,
    .terminal-output > :not(.raw) div, 
    .cmd, .cmd span, .cmd div {
        color: var(--color, #aaa);
        background-color: var(--background, #000);
    }
    .terminal, .terminal-output > :not(.raw) span, 
    .terminal-output > :not(.raw) a, 
    .terminal-output > :not(.raw) div, 
    .cmd, .cmd span, .cmd div {
        font-family: monospace;
        color: #aaa;
        background-color: #000;
        font-size: 12px;
        line-height: 14px;
    }
    .terminal .terminal-output > div:not(.raw) div {
        white-space: nowrap;
    }
    Style Attribute {
        --char-width: 7.23011;
    }
    .terminal, .cmd {
        box-sizing: border-box;
        cursor: text;
    }
    

    这是密码笔 https://codepen.io/jcubic/pen/wQjaZv

    我可以通过添加 padding-bottom: 1px; margin-bottom: 1px .terminal-output > div > div 但我想知道为什么会这样?为什么第二行的下划线可见,而第一行的下划线不可见?

    我没有在这支笔中使用任何重置或规范化css。

    编辑 :

    /* FireFox hack */
    @supports (-moz-animation: foo) {
        .terminal,
        .terminal .terminal-output > :not(.raw) span,
        .terminal .terminal-output > :not(.raw) a,
        .terminal .terminal-output > :not(.raw) div,
        .cmd,
        .cmd span,
        .cmd div {
            line-height: calc(var(--size, 1) * 13px);
        }
    }
    

    这可能会解决firefox的一些问题,但如果没有它,它似乎可以工作。

    当我在Chrome/Linux/Codpen的开发工具中进行调查时,我发现ASCII艺术线条如下(以计算方式):

    line div parent {
       height: 13.9915px;
    }
    span child {
       height: 13.6364px;
    }
    

    line div parent {
       height: 14px;
    }
    span child {
       height: 14px;
    }
    

    当我悬停在line div上时,我的高度是15。

    .terminal .terminal-output > div > div {
        min-height: calc(var(--size, 1) * 14px);
    }
    

    它至少应该是14px,为什么它有 13.9915px ?

    我又做了一次测试,我克隆了codepen编辑器,插入调试页面作为iframe源,保存并上传到我的服务器,它也工作正常,div没有被切断,高度为14px。

    :

    .terminal .terminal-output > div > div {
        min-height: calc(var(--size, 1) * 15px);
    }
    

    15px 而不是 14px 但仍然想知道为什么会发生这种情况,为什么只在Codepen/Linux/Chromium上发生。

    1 回复  |  直到 7 年前
        1
  •  1
  •   yunzen    7 年前
    .terminal, 
    .terminal-output > :not(.raw) span, 
    .terminal-output > :not(.raw) a, 
    .terminal-output > :not(.raw) div, 
    .cmd, 
    .cmd span, 
    .cmd div {
      font-size: calc(var(--size, 1) * 20px);
      line-height: calc(var(--size, 1) * 24px);
    }
    

    下划线被截断,因为满足了行高度的限制,并且每行都有一个背景色。如果同时增加线条高度,它将再次工作

    p {
      white-space: pre;
      font-family: monospace;
    }
    #one {
      font-size: 14px;
      line-height: 7px;
    }
    
    #two {
      font-size: 14px;
      line-height: 8px;
    }
    
    span {
      background: white;
      
    }
    <p id="one">
      <span>      __ _____                     ________                              __</span><br>
      <span>     / // _  /__ __ _____ ___ __ _/__  ___/__ ___ ______ __ __  __ ___  / /</span><br>
      <span> __ / // // // // // _  // _// // / / // _  // _//     // //  \/ // _ \/ /</span><br>
      <span>/  / // // // // // ___// / / // / / // ___// / / / / // // /\  // // / /__</span><br>
      <span>\___//____ \\___//____//_/ _\_  / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/</span><br>
      <span>          \/              /____/                                  v. 2.0.1</span>
    </p>
    <p id="two">
      <span>      __ _____                     ________                              __</span><br>
      <span>     / // _  /__ __ _____ ___ __ _/__  ___/__ ___ ______ __ __  __ ___  / /</span><br>
      <span> __ / // // // // // _  // _// // / / // _  // _//     // //  \/ // _ \/ /</span><br>
      <span>/  / // // // // // ___// / / // / / // ___// / / / / // // /\  // // / /__</span><br>
      <span>\___//____ \\___//____//_/ _\_  / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/</span><br>
      <span>          \/              /____/                                  v. 2.0.1</span>
    </p>