How to render multi-line text component with white gap between lines, but with display:inline-block
property? I have a code
tag with multiline text, which is supposed to have attribute display: inline-block. I was told not to change content or the display property but to make somehow gap between lines, so background-color property affects only one single line. Is it even possible with display: inline-block?
I found pretty close issue How to render multi-line Text component with white gap between lines, but the example there works with display: inline. Above 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>
CodePudding user response:
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>
CodePudding user response:
Remember what "inline-block" means: the content inside the element will be displayed as a box (block), not inline. This will remove the white gaps between each line of text.
To display the gaps as desired, you can add a wrapper element inside the outer element.
code {
display: inline-block;
}
code span {
background-color: aqua;
line-height: 1.5;
}
/* Make <code> sit next to the prior element */
code {
max-width: 25em;
}
<span>Some content</span>
<code>
<span>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).</span>
</code>