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?
-
Please post the code in a snippet (See illustration), jsFiddle.net, PenCode.io, or Plnkr.cozer00ne– zer00ne2015-12-28 17:40:40 +00:00Commented Dec 28, 2015 at 17:40
-
Please find the jsFiddle... linkSivadass N– Sivadass N2015-12-28 18:12:13 +00:00Commented 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.user663031– user6630312015-12-28 18:54:09 +00:00Commented Dec 28, 2015 at 18:54
Add a comment
|
2 Answers
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>
5 Comments
herrh
@Sivadass: Okay, hope the edited solution will help.
Sivadass N
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...
herrh
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.
Sivadass N
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...
herrh
You are right. For shorts texts with 20-24 characters a <span> will be the correct tag.
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
Sivadass N
Title will vary for each product, so I can't only hide "500 sheets"?
zer00ne
I'll add different content and see how it looks.
zer00ne
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.