html - 如何通过 CSS 在文本后面添加一个突出显示,使其看起来像下面的 Instagram-one?

标签 html css

我对 CSS\HTML 还是很陌生。我如何通过 CSS 做同样的事情:

Instagram highlight

我试过了:

.works_title {
  display: inline;
  padding: 3px;
  font-size: 28px;
  font-weight: 700;
  color: aliceblue;
  background-color: #000;
  border-radius: 4px;
}


body {
 max-width:300px;
}
<div class="works_title">Something long, like a title with bunch of letters</div>

但它看起来不像 Instagram 故事编辑器中的样子。我在网络中需要这样的东西。谢谢!

最佳答案

您可以使用 box-decoration-break: clone; 然后考虑使用 SVG 过滤器以使效果更好。

更新 stdDeviation 变量以控制形状:

.works_title {
  display: inline;
  padding: 4px 6px;
  line-height:1.4; /* adjust this to avoid overlapping the padding */
  font-size: 28px;
  font-weight: 700;
  color: aliceblue;
  background-color: red;
  border-radius: 4px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  filter: url('#instagram');
}
.no-filter {
  filter:none;
}

body {
  max-width: 250px;
}
<div class="works_title">Something longlike a title with bunchofletters a more text</div>
<br>
<br>
<div class="works_title no-filter">Something longlike a title with bunchofletters a more text</div>

<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
    <defs>
        <filter id="instagram">
            <feGaussianBlur in="SourceGraphic" stdDeviation="5" result="blur" />    
            <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 20 -8" result="goo" />
            <feComposite in="SourceGraphic" in2="goo" operator="atop"/>
        </filter>
    </defs>
</svg>

CSS highlight text instagram style

关于html - 如何通过 CSS 在文本后面添加一个突出显示,使其看起来像下面的 Instagram-one?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62341132/

相关文章:

html - img-responsive 不居中

css - 如何设计这样的div和菜单

css - 将 CSS 放在应用程序的不同部分会产生不同的效果

css - 响应式菜单 : vertical on smaller but horizontal on larger screen

html - 用于 HTML 和 CSS 中的双面打印的甚至分页符

javascript - JS添加css类时如何应用css代码样式

javascript - 在随机 div 上使用 insertAfter 选项

html - 需要添加指向图库的链接

html - 使图像完全填满单元格

javascript - Rich文本输入框-溢出问题