4

I am showing product title inside a <span>. I want the title to be truncated when there is no enough space. I tried text-overflow: clipping, but its not taking the padding which is applied on right side. So I used text-overflow: ellipsis, it works fine, but I don't wanna keep that "..." 3 dots at the end. Is there any way to hide or remove it by css?

3
  • Please post the code in a snippet (See illustration), jsFiddle.net, PenCode.io, or Plnkr.co Commented Dec 28, 2015 at 17:40
  • Please find the jsFiddle... link Commented Dec 28, 2015 at 18:12
  • There are a couple of ways to track down an error like this. For example, run your CSS through a linter; or view the element in the style inspector in your debugger. Either way would show you the invalid property value. Commented Dec 28, 2015 at 18:54

2 Answers 2

11

You should try clip instead of clipping.

text-overflow:clip;

=====

EDIT:

This should fix your problem:

.clipping-wrapper {
    border: 1px solid #4099ff;
    padding: 0 40px;
    display: inline-block;
}
.clipping{
    white-space: nowrap; 
    width: 200px; 
    overflow: hidden;
    text-overflow: clip; 
}
<div class="clipping-wrapper">
  <p class="clipping">
    Copier Paper A4 Size - 70Gsm (500 Sheets)
  </p>
</div>

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

5 Comments

@Sivadass: Okay, hope the edited solution will help.
Thanks @herrh, it works :) I have one doubt, is it wrong semantic to wrap a single line of text with <span> inside a div??? Please clarify me this if you are free...
span is an inline element and used to style specific text parts of a paragraph. Can't you use <p> instead of <span> in your project? PS: Please accept the answer if it shows a working solution.
Accepted the answer, but am still not clear why I should use <p> instead of <span> tag for a single line of text which is not going to be more than 20-24 Characters...
You are right. For shorts texts with 20-24 characters a <span> will be the correct tag.
0

Made something different

  • Eliminated the text-overflow
  • Made the ' (500 Sheets)' string to CSS generated content a:after { content: ...
  • To hide it it's font-size: 0
  • On hover, the ' (500 Sheets)' is revealed.

.clip {
  float: left;
  display: inline-block;
  white-space: nowrap;
  width: 200px;
  overflow: hidden;
  border: 1px solid #4099ff;
  padding: 0 40px;
}
.clip.a:after {
  content: ' (500 Sheets)';
  display: inline-block;
  font-size: 0;
}
.clip.b:after {
  content: ' (Free Recycling)';
  display: inline-block;
  font-size: 0;
}
.clip.c:after {
  content: ' (20 per Box)';
  display: inline-block;
  font-size: 0;
}
.clip.d:after {
  content: '';
  display: inline-block;
  font-size: 0;
}
.clip:hover {
  overflow: visible;
  padding-right: 80px;
}
.clip:hover:after {
  font-size: 1rem;
  background-color: inherit:
}
<div>
  <span class="clip a">
    Copier Paper A4 Size - 70Gsm
  </span>
</div>

<div>
  <span class="clip b">
    3M Copy Toner Cartridge - 
  </span>
</div>

<div>
  <span class="clip c">
    No. 2 Graphite Pencils - 
  </span>
</div>

<div>
  <span class="clip d">
   Paper Clips - 200 per Box
  </span>
</div>

3 Comments

Title will vary for each product, so I can't only hide "500 sheets"?
I'll add different content and see how it looks.
Fair enough. herth's is the way to go. I came up with the same solution as he did, which is why I took an alternate route.

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.