Here is the problem:
- I have a list of items with various length for then name.
- I want to trim the names to 140 pixels if they are longer.
- As a nice clean way
of demonstrating to users that the string is trimmed, I want to
reduce transparency of the last few characters of the name, or at
least create that illusion. - I do not want to use the ellipsis… effect for several good reasons.
I this possible in pure CSS?
Sure can, using CSS. You have two options, but really only the first will get the best results cross-browser.
The idea is to overlay a pseudo-element over the right of your element containing the string. This will only work if it’s on a solid background color, as we will use that color to “fade” to.
HTML
CSS
the
:afterelement will work in all browsers, IE8+. The-ms-gradientonly in IE10+, so either figure out how to use the old ie gradient filters, or use a PNG image.There’s also another newer CSS method, but currently only supported by webkit (Chrome & Safari),
mask-image. Here, you can use an image or a CSS gradient to mask an element. Same principal, except you can actually fade the element (in the case your text was on a patter).You can check out this jsfiddle: http://jsfiddle.net/rgthree/b96sv/