使用以下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%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
background: -o-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
background: -ms-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
background: linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 );
}
JS Fiddle演示。
当然,您也可以在生成的内容中使用百分比宽度:JS Fiddle概念验证。
在下面的评论中作出回应后进行编辑,报告称IE 8(以及可能更低版本)与以上解决方案不兼容:
但对我来说,在IE8中无法工作...
我更新了以下HTML:
<div>
<span>@someUserName
</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%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
background: -o-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
background: -ms-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
background: linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 );
}
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 );
}
JS Fiddle演示链接,在Win XP/IE 8和Chrome 18(与以前一样)中有效。
参考: