html – 如何在多行文本中的每一行应用填充?

前端之家收集整理的这篇文章主要介绍了html – 如何在多行文本中的每一行应用填充?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我将背景颜色应用于< span>标签,还有左右填充.问题是:当文本被包裹在几行上时,填充仅应用于< span>的左(开始)和右(结束),而不是每行的左(开始)和右(结束).

如何将左右的填充应用于中间线?

h1 {
  font-weight: 800;
  font-size: 5em;
  line-height: 1.35em;
  margin-bottom: 40px;
  color: #fff;
}
h1 span {
  background-color: rgba(0,0.5);
  padding: 0 20px;
}
<h1><span>The quick brown fox jumps over the lazy dog.</span></h1>

解决方法

您可以使用具有克隆值的Box-decoration-break属性.

Box-decoration-break: clone; Each Box fragment is rendered independently with the specified border,padding and margin wrapping each fragment. The border-radius,border-image and Box-shadow,are applied to each fragment independently. The background is drawn independently in each fragment which means that a background image with background-repeat: no-repeat may be repeated multiple times. – 07000

请参阅caniuse.com的当前浏览器支持

jsFiddle example

h1 {
  font-weight: 800;
  font-size: 5em;
  line-height: 1.35em;
  margin-bottom: 40px;
  color: #fff;
}
h1 span { 
  background-color: rgba(0,0.5); 
  padding: 0 20px;
  -webkit-Box-decoration-break: clone;
  Box-decoration-break: clone;
}
<h1><span>The quick brown fox jumps over the lazy dog.</span></h1>

猜你在找的HTML相关文章