css文本背景与文本行之间的空间不同

发布于 2024-10-22 23:59:16 字数 195 浏览 4 评论 0原文

我有一些格式化文本:链接到 JSFiddle 我想让它看起来像这样:

在此处输入图像描述

如何做到这一点?

I have some formatted text : link to JSFiddle
and i want to make it to look like this :

enter image description here

How can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海之角 2024-10-29 23:59:16

这里是..

.news_text{
  position:relative;
  float:left;
  font-family:Arial, Helvetica, sans-serif;
  font-size:11px;
  width:220px;
  background-color:#866b62;
  color:#FFF;
  padding:3px;

  line-height: 1.2em;  /*notice line-height*/ 
  overflow: hidden;  /*to hide extra transform*/ 
}
.news_text::before{
 background:repeating-linear-gradient(transparent,transparent calc(1.2em - 1px),white calc(1.2em - 1px),white calc(1.2em + 0px)); /*that same line-height*/
  background-repeat: repeat-y;
 content: '';
 position:absolute;
 top:3px; /*same as padding*/
 bottom: 1em; /*use with care when handling padding*/
 left:0;
 right: 0;
}
.news_text::after{
 content:'------';  /*'' blank was not working on inline-block*/
 color:transparent; /*to hide '------'*/
 background-color: white; /*same as background*/ 
 position: relative;
 display: inline-block;
 transform-origin: top left;
 transform:scale(20,2) scaleY(1.1); /*adjust based on your content*/
}
<span id="news_text" class="news_text">
  Maecenas tempus rhoncus nisl, eu lorem blandit a consectetuer adipiscing
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur libero nobis, ut itaque, quibusdam, cumque corporis optio dignissimos consequatur voluptatum cum, provident officia
</span> 

不知道为什么我花了那么多时间在上面......

Here it is..

.news_text{
  position:relative;
  float:left;
  font-family:Arial, Helvetica, sans-serif;
  font-size:11px;
  width:220px;
  background-color:#866b62;
  color:#FFF;
  padding:3px;

  line-height: 1.2em;  /*notice line-height*/ 
  overflow: hidden;  /*to hide extra transform*/ 
}
.news_text::before{
 background:repeating-linear-gradient(transparent,transparent calc(1.2em - 1px),white calc(1.2em - 1px),white calc(1.2em + 0px)); /*that same line-height*/
  background-repeat: repeat-y;
 content: '';
 position:absolute;
 top:3px; /*same as padding*/
 bottom: 1em; /*use with care when handling padding*/
 left:0;
 right: 0;
}
.news_text::after{
 content:'------';  /*'' blank was not working on inline-block*/
 color:transparent; /*to hide '------'*/
 background-color: white; /*same as background*/ 
 position: relative;
 display: inline-block;
 transform-origin: top left;
 transform:scale(20,2) scaleY(1.1); /*adjust based on your content*/
}
<span id="news_text" class="news_text">
  Maecenas tempus rhoncus nisl, eu lorem blandit a consectetuer adipiscing
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur libero nobis, ut itaque, quibusdam, cumque corporis optio dignissimos consequatur voluptatum cum, provident officia
</span> 

Don't know why I spent so much time on it....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文