4

I really like how twitter blur the end of the long name, when you move the cursor on the box with message.

I would like to try make something similar, with a little difference - I have a DIV (let's say width: 100px;) and when a text inside is longer then 100px - then will be the end of the respective text blurred...

Could anyone give me some example/source/advice, how to do that?

Thank you

example

4

2 に答える 2

10

次の 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 フィドルのデモ

もちろん、生成されたコンテンツでパーセンテージ幅を使用することもできます: JS Fiddle の概念実証


以下のコメントに応じて編集され、IE 8 (およびおそらくそれ以下) は上記のソリューションでは機能しないことが報告されています。

ただし、IE8では機能しません...

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 */

}​

Win XP/IE 8 および Chrome 18 (以前と同様) で動作する JS Fiddle デモ

参考文献:

于 2012-04-24T11:54:11.470 に答える
3

その上に別のDIVを配置し、完全に透明から完全に白にフェードする半透明のPNG背景を指定します。何かのようなもの:

<div style="position: relative; width: 100px">
    @GuyKawasaki
   <div style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; background-image:url(overlay.png)"></div>
</div>
于 2012-04-24T11:43:28.360 に答える