Forum Bugs

font-size:0; causing a glitch in line height

adriencater
I have a slightly complicated situation, where I need to hide/remove some spans from the document.

I cannot use {display:none;} because this transforms the span into a block element, and this in turn causes issues with spaces appearing around the removed item.

Other approaches such as {width:0;} which require a block display also cause an errant space to appear (the document a very very complicated and verbose markup, with index items abutting footnote references etc.)

The only solution I have found which successfully 'removes' the element without causing a space to appear is {font-size:0;}

(details here: https://css-tricks.com/fighting-the-space-between-inline-block-elements/)

Unfortunately, font-size:0; causes an increase in the line height in the following line of the document.

a) is there any other way to hide inline items?

b) is there any fix for this line-height glitch?

Sample HTML showing the line height glitch:


<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Font size zero test</title>
    <style>
      p { font-size: 10pt; line-height: 5mm; }
      .hideMe { font-size:0; }
    </style>
  </head>
  <body>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute<span class="hideMe">irure dolor</span> in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  </body>
</html>

Edited by adriencater

mikeday
Wait what's wrong with applying display: none in this document?
adriencater
The sample document above only shows the difference in line height.

My production document (a 900 page book of Word-generated html spaghetti code) is showing the phantom space issue.

Screencap shows some testing:

Top document shows the to-be-removed items with a magenta background, footnote calls are in cyan.

Middle document shows the result of display:none; – I've highlighted the phantom spaces that appear when the pink items are set to display:none.

Bottom document shows font-size:0; – the phantom spaces after the pink items are gone, but the lines in question have an extra vertical space to the next line.
  1. compare-visible-display-none-font-size-0.png751.5 kB
    Compare display none and font-size 0
mikeday
I see, can you check the markup around the display none element to see exactly where the spaces occur, and whether any other style properties are applied?

Reducing the font size increasing the line height is counterintuitive but compatible with browsers; to be honest I forget the exact reason this happens and will need to look it up. :D
mikeday
It may be necessary to use JavaScript to surgically remove any unnecessary whitespace, depending on exactly how the markup is structured.
adriencater
Thanks for looking into it, Mike.

We'll go back and adjust our document filters to try to zap the errant space so that display:none; works – if you have any suggestions for tests I could run to keep the line height in check, I'll give them a run.

I only wanted to bring it to your attention since there are some non-obvious things happening: the space dis/appearing based on the display properties of an item; and the line-height fluctuating or vertical space being added.

mikeday
It would be possible to check for unexpected line height variations with JavaScript using the box tracking API, although for some documents there might be many false positives if the line height is actually supposed to vary in some places.
adriencater
We found a fix for the line-height issue:

Adding a line-height:0; fixes the issue.

 .hideMe { font-size:0; line-height:0; } 


Yay!

mikeday
Ah yes why didn't I think of that! :D