1

I have a very small issue for someone whose have command over css. I have the following markup:

<li>
 <div>
  <span>Some text</span>
  <span>Some large amount of text</span>
 </div>
<li>

And the css is :

li
{
  width: 150px;
  height: 100px;
}

Now i want to show ellipsis inside second span which contains large amount of text. How can i do this ?

Can anybody please help me ?

0

5 Answers 5

2

Not sure why you showed us how you styled the lis but…

<style>
li > span:nth-child(2):before {
    content: '\2026\0020';
}
</style>
<li>
    <span>Some text</span>
    <span>Some large amount of text</span>
</li>

In Unicode, U+2026 is the horizontal ellipsis and U+0020 is the space.

Demo: http://jsfiddle.net/5xWhx/

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

1 Comment

I misunderstood the asker. Please disregard this answer.
1

Assuming your structure is always like you've marked up (if not, you can use classes - probably a better approach anyway), you can use the nth-child selector and :after (or ::after) pseudo-elements, you can do it like this:

<ul>
<li>
 <div>
  <span>Some text</span>
  <span>Some large amount of text</span>
 </div>
 </li>
 </ul>

CSS:

/* Hide the text in the second span */
li span:nth-child(2){
    display:block;
    overflow:hidden;
    text-indent:100%;
    white-space:nowrap;
}

/* Create a pseudo-element after the first span with an ellipsis (UTF-8) as its content */
li span:nth-child(1):after{
    content:" \2026";
}

jsFiddle Example

Comments

1

All you need is this if you have only one liner span. No pseudo elements required

li span:nth-child(2) {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

According to caniuse.com all browser support this.

Comments

0

Try this plugin -

http://plugins.jquery.com/ellipsis/

$('#target').ellipsis({
    row: 2,
    char: '**'
});

You can also try this way (not fully supported)

span{
    /* essential */
    text-overflow: ellipsis;
    width: 200px;
    white-space: nowrap;
    overflow: hidden;

    /* for good looks */
    padding: 10px;
}

3 Comments

thanks for response but is there any pure css approach to do this ?
Make sure you also apply display:block to span.
CSS text-overflow is fully supported in all browsers. The only exception is if there are still people using Firefox 6 or earlier, which is virtually nobody. There's not need to bother with the jquery option for a basic ellipsis.
0

I'm not sure if from your example wether you need a dynamic solution of not. So a few questions for you

  • Do you know for sure that there will always be more text than the
    container can show?
  • Is this text in second span shown only on one line or multiple lines?

I ask this because the text-overflow:ellipsis; only works on single line and then only in combination with white-space:nowrap;

Comments

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.