gpt4 book ai didi

html - CSS - 如何使单词的结尾变得模糊?

转载 作者:技术小花猫 更新时间:2023-10-29 11:49:05 24 4
gpt4 key购买 nike

当您将光标移动到包含消息的框上时,我真的很喜欢 twitter 如何模糊长名称的结尾。

我想尝试做一些类似的东西,但有一点不同——我有一个 DIV(比如 width: 100px;),当里面的文本长于 100px 时——那么将是相应文本的结尾模糊...

谁能给我一些例子/来源/建议,怎么做?

谢谢

example

最佳答案

使用以下 HTML:

<div>
<span>@someUserName</span>
</div>​

和 CSS:

span {
display: inline-block;
position: relative;
}

span::after {
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 3em;
content: '';
background: -moz-linear-gradient(left, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(100%,rgba(255,255,255,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* IE10+ */
background: linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 ); /* IE6-9 */
}​

JS Fiddle demo .

当然,您也可以在生成的内容中使用百分比宽度:JS Fiddle proof of concept .


编辑 以响应下面的评论,报告 IE 8(可能更低)不适用于上述解决方案:

not working for me in IE8 though...

我已将 HTML 更新为以下内容:

<div>
<span>@someUserName
<!--[if ie]>
<span class="ieFadeout"></span>
<![endif]-->
</span>
</div>​

并更新了 CSS:

div > span {
display: inline-block;
position: relative;
}

div > span::after {
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 3em;
content: '';
background: -moz-linear-gradient(left, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(100%,rgba(255,255,255,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* IE10+ */
background: linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 ); /* IE6-9 */
}

span > .ieFadeout {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 3em;
background-color: transparent;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 ); /* IE6-9 */

}​

JS Fiddle demo, working in Win XP/IE 8, and Chrome 18 (as before) .

引用资料:

关于html - CSS - 如何使单词的结尾变得模糊?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10297137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com