<small id='hLJct'></small><noframes id='hLJct'>

    1. <tfoot id='hLJct'></tfoot>

      <legend id='hLJct'><style id='hLJct'><dir id='hLJct'><q id='hLJct'></q></dir></style></legend>
    2. <i id='hLJct'><tr id='hLJct'><dt id='hLJct'><q id='hLJct'><span id='hLJct'><b id='hLJct'><form id='hLJct'><ins id='hLJct'></ins><ul id='hLJct'></ul><sub id='hLJct'></sub></form><legend id='hLJct'></legend><bdo id='hLJct'><pre id='hLJct'><center id='hLJct'></center></pre></bdo></b><th id='hLJct'></th></span></q></dt></tr></i><div id='hLJct'><tfoot id='hLJct'></tfoot><dl id='hLJct'><fieldset id='hLJct'></fieldset></dl></div>
        <bdo id='hLJct'></bdo><ul id='hLJct'></ul>

      1. 消除 HTML5 画布元素下方的幽灵边距?

        时间:2023-06-20
      2. <tfoot id='Ber7w'></tfoot>

        <small id='Ber7w'></small><noframes id='Ber7w'>

          <bdo id='Ber7w'></bdo><ul id='Ber7w'></ul>
              <i id='Ber7w'><tr id='Ber7w'><dt id='Ber7w'><q id='Ber7w'><span id='Ber7w'><b id='Ber7w'><form id='Ber7w'><ins id='Ber7w'></ins><ul id='Ber7w'></ul><sub id='Ber7w'></sub></form><legend id='Ber7w'></legend><bdo id='Ber7w'><pre id='Ber7w'><center id='Ber7w'></center></pre></bdo></b><th id='Ber7w'></th></span></q></dt></tr></i><div id='Ber7w'><tfoot id='Ber7w'></tfoot><dl id='Ber7w'><fieldset id='Ber7w'></fieldset></dl></div>
              <legend id='Ber7w'><style id='Ber7w'><dir id='Ber7w'><q id='Ber7w'></q></dir></style></legend>
                    <tbody id='Ber7w'></tbody>
                  本文介绍了消除 HTML5 画布元素下方的幽灵边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我们创建 HTML5 画布元素时,即使我们将边距和内边距设置为 0,画布元素下方也会出现幻影边距.

                  When we create an HTML5 canvas element, a ghost margin appears below the canvas element even though we set the margin and padding to 0.

                  示例:http://jsfiddle.net/yvbmd/

                  我们尝试了各种方法,但无法擦除鬼边.

                  We tried a variety of things, but can't erase the ghost margin.

                  我们如何创建没有幽灵边距的画布元素?

                  How can we create the canvas element without that ghost margin?

                  推荐答案

                  添加vertical-align: bottom.

                  这是由于画布是内联元素造成的.因此,它实际上被视为一个角色.因此,它必须遵循基线规则,即在 gjpqy 等字符低于基线的情况下,在行下方留出一点空间.通过将 vertical-align 设置为 bottom,实际上是将画布与下拉字母的底部对齐.只要画布本身高于line-height,就没有问题.如果画布比 line-height 短,您将开始在画布上方看到幽灵边距",因为它为 bdfhklt(较高的字母)保留了空间.这可以通过添加 line-height: 1px 规则来解决.

                  This is caused by the canvas being an inline element. As such, it is effectively considered a character. As such, it must follow the baseline rule, which is to leave a little space below the line in case of characters such as gjpqy which drop below the baseline. By setting the vertical-align to bottom, you are actually aligning the canvas to the bottom of the drop-down letters. So long as the canvas itself is taller than the line-height, you will have no problems. Should the canvas be shorter than the line-height, you will start seeing "ghost margins" above the canvas as it reserves room for bdfhklt, the taller letters. This can be fixed by adding a line-height: 1px rule.

                  这篇关于消除 HTML5 画布元素下方的幽灵边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:是否可以创建没有 DOM 元素的 HTML 画布? 下一篇:HTML5 画布调整为父级

                  相关文章

                  1. <tfoot id='39y3T'></tfoot>

                      <legend id='39y3T'><style id='39y3T'><dir id='39y3T'><q id='39y3T'></q></dir></style></legend>
                      <i id='39y3T'><tr id='39y3T'><dt id='39y3T'><q id='39y3T'><span id='39y3T'><b id='39y3T'><form id='39y3T'><ins id='39y3T'></ins><ul id='39y3T'></ul><sub id='39y3T'></sub></form><legend id='39y3T'></legend><bdo id='39y3T'><pre id='39y3T'><center id='39y3T'></center></pre></bdo></b><th id='39y3T'></th></span></q></dt></tr></i><div id='39y3T'><tfoot id='39y3T'></tfoot><dl id='39y3T'><fieldset id='39y3T'></fieldset></dl></div>

                      <small id='39y3T'></small><noframes id='39y3T'>

                        <bdo id='39y3T'></bdo><ul id='39y3T'></ul>