2

Is it actually possible to use text-overflow: ellipsis, when you don't set the width? Instead of width I need to set it until 100px from the right. If the text reaches 100px from the right, it will be hidden and with dots in the front.

3 Answers 3

2

You should just have to add padding-right: 100px; to the element with text in.

HTML

<p>some text</p> 

CSS

p { text-overflow: ellipsis; padding-right: 100px; white-space: nowrap; overflow: hidden; } 

Here is a JsFiddle with the above code.

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

2 Comments

yeah, but the thing is I need to use text-align: center and it'd not centered anymore if I use padding-right.
Change the padding to padding: 0 100px; ?
0

You can use both margins: left and right to make it work:

HTML: <div class="parent"> <div class="test">some pseudo-centered text some pseudo-centered text some pseudo-centered text some pseudo-centered text some pseudo-centered text</div> </div> CSS: .test { text-align: center; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; margin: 0 100px; } 

A working example online can be seen here: http://jsfiddle.net/rqb3W/1/

Comments

0

text-overflow: ellipsis only works if width or max-width is set in pixels. You can get around this by using width: calc (69%) which gets converted to px.

So to answer your question you can try float:right with a margin or use width: calc(100% - 100px); with margin-right: 100px

Refer: https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.