3

ellipsis will add '...' to text by default if we have 'text-overflow: ellipsis', but my scenario i need to overide this by two stars * *. How we can achieve this is Pure CSS?

Note: It should support All browsers like IE9+ and chrome

As some peoples asking example adding this, http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_text-overflow

9
  • For doing this you need javascript. Its not possible with pure css Commented Dec 26, 2016 at 13:29
  • Could you post your code? Commented Dec 26, 2016 at 13:30
  • @priya_singh: Expecting CSS workaround. Hoping some CSS experts will help me Commented Dec 26, 2016 at 13:30
  • @NenadVracar: Example added Commented Dec 26, 2016 at 13:32
  • This will not really work exactly as the css's ellipsis feature, but it can give you a hint of how to create something similar: jsfiddle.net/dekelb/vuxfk0hk Commented Dec 26, 2016 at 13:39

1 Answer 1

5

You can apply a trick using pseudo elements like :after.

Have a look at the snippet below:

#div1 {
  position: relative;
  white-space: nowrap; 
  width: 99px; 
  overflow: hidden;
  text-overflow: ellipsis; 
  border: 1px solid #000000;
}

#div1:after {
  content: '**';
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  background: #fff;
  padding: 0 2px 0 0;
}
<p>This div uses "text-overflow:ellipsis":</p>
<div id="div1">This is some long text that will not fit in the box</div>

Hope this helps!

Sign up to request clarification or add additional context in comments.

6 Comments

Change width: 99px; character cutted to half
@LearnReact Updated the answer. Try it now.
Sorry bro, Can you check with width: 89px; it is breaking
The :after pseudo class will not work the same as the ellipsis. You will have to check if you have enough content to cut&display the ellipsis, and you can't really do this with the :after pseudo class.
@LearnReact I agree with Dekel. This will not work as same as ellipsis. This is just a trick to override ellipsis.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.