Search code examples
cssinline

Render multi-line text component with white gap between lines with display:inline-block


How can I render a multi-line text component with white gaps between the lines? The component must use display: inline-block.

I have a <code> tag with multi-line text. I was told not to change content or the display property, but to somehow make gaps between lines, so that the background-color property affects only one single line. Is it even possible with display: inline-block?

I found another similar question, but the example there works with display: inline.

Here is what I'm trying to get:

code {
  background-color: aqua;
  line-height: 1.5;
}
<code>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humor and the like).</code>


Solution

  • You can consider a gradient coloration that you combine with inline-block

    code {
      display: inline-block;
      background: linear-gradient(0deg,#0000 5px,aqua 0) 0 2px/100% 1.5em;
      line-height: 1.5;
    }
    <code>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humor and the like).</code>