简体   繁体   English

删除大写标题周围的空格

[英]Remove space around uppercase header

I have a title which is displayed in uppercase letters. 我有一个用大写字母显示的标题。 I would like to have just 2 pixels between this title and the framed box below. 我想在这个标题和下面的框架框之间只有2个像素。

If the text contains lowercase letters like 'g', there is no space below, but once all 'g', 'y' and 'j' letters are gone, it appears. 如果文本包含像'g'这样的小写字母,则下面没有空格,但是一旦所有'g','y'和'j'字母都消失了,就会出现。

Is there any cross-browser method of getting rid of that space? 是否有任何跨浏览器方法摆脱那个空间? Apparently browsers display different amount of empty space: https://jsfiddle.net/5o94va6p/13/ , so tricks like line-height: 0.7 work in Firefox but eat too much space in Safari. 显然浏览器会显示不同数量的空白区域: https//jsfiddle.net/5o94va6p/13/ ,所以像line-height: 0.7这样的技巧line-height: 0.7在Firefox中工作但在Safari中占用太多空间。

Safari and chrome look similar in terms of empty space. Safari和chrome在空白空间方面看起来相似。 The browser that looks different is Firefox. 看起来不同的浏览器是Firefox。 I would only specify line height for it using CSS. 我只会使用CSS为它指定行高。 This way, Firefox will look good, and it will not effect the look in other browsers. 这样,Firefox看起来不错,并且不会影响其他浏览器的外观。

Try this code which will target only Firefox: 试试这个仅针对Firefox的代码:

@-moz-document url-prefix() {
    h1 {
       line-height: 0.7
    }
}

try using this - 试着用这个 -

.box{
  margin-top: 2px;
  position: fixed;
}

The space below the baseline which is needed for letter like y, g, p etc. is ALWAYS there, it's part of the line-height - this is the reason for your problem. 像y,g,p等字母所需的基线下面的空间始终存在,它是线高的一部分 - 这就是你问题的原因。 You can't change that unless you define a negative margin-bottom value, like 除非您定义负边距底值,否则无法更改

.my_heading {
  margin-bottom: -4px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM