如何渲染多行文本组件,行与行之间有白色间隙,但有display:inline-block个属性?我有一个带有多行文本的code标记,它应该有属性DISPLAY:INLINE-BLOCK.我被告知不要更改内容或显示属性,而是要在行之间留出一定的间距,这样背景色属性就只影响一行.是否可以使用Display:Inline-BLOCK?

我发现了非常接近的问题How to render multi-line Text component with white gap between lines,但那里的示例适用于Display:Inline. 以上是我想要得到的:

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>

推荐答案

您可以考虑将渐变 colored颜色 与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>

Css相关问答推荐

如何将div与图像维度进行zoom ?

如何在CSS中平滑线性平移动画

如何在css中创建文件div效果

如何为图像堆叠效果下方的图层实现与磨砂玻璃类似的视觉效果

在具有特定类的 td 之后,如何编写适用于该行上所有 td 元素的表行的 CSS Select 器?

应用边框半径的 iframe 在 4 个角上有细曲线

SCSS - Lighten/Darken 不编译?

使用 React 和 Flexbox 文本溢出框外

我怎样才能将我的按钮向上移动,因为文本是

对齐视图中的复选框(RN)

如何将 .btn-group 从 twitter-bootstrap 居中?

如何使单选按钮看起来像切换按钮

CSS 中的区域类似于 C# 区域?

CSS,居中的 div,缩小以适应?

如何将页脚保持在屏幕底部

如何在需要时通过 HTTPS 包含 CSS 和 JS 文件?

位置固定宽度 100%

从样式设置为 % 的元素获取宽度(以像素为单位)?

bootstrap 关闭响应菜单点击

CSS 边距和填充速记属性顺序的助记符