Span width is not reduced after ellipsis in CSS - html

I have 1 parent li element with 2 child spans in it.
My first span has large title so i applied ellipsis to the parent li.
My issue is when the 1st span is ellipsis, The 2nd span which should aligned next to it is being place after the full width of 1st span.
To be more clear, 1st span is title and 2nd span is count.
#title {
color: black;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 200px;
}
#view-count {
font-size: 10px;
margin-left: 4px;
border-radius: 10px;
line-height: 1;
position: absolute;
top: 30%;
}
<li id="title" title="Documentationxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
<span>Documentationxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</span>
<span id="view-count">370</span>
</li>
Below is the JSFiddle for it.
JSFiddle
Any help?

You have to apply ellipsis to first span and have to remove position from second span.
Check snippet.
#title {
color: black;
position: relative;
width: 240px;
}
.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 200px;
}
span {
display: inline-block;
}
#view-count {
font-size: 10px;
margin-left: 4px;
border-radius: 10px;
line-height: 1;
position: absolute;
z-index: 1;
background: #ff0000;
top: -5px;
right: 0;
}
<li id="title" title="Documentationxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
<span class="ellipsis">Documentationxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</span>
<span id="view-count">370</span>
</li>

You can use flex for this:
.title {
display: flex;
width: 200px;
}
.title > span:nth-child(1) {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1 1 auto;
background-color: #FC0;
}
.title > span:nth-child(2) {
flex: 0 0 auto;
background-color: #CF0;
}
<ul>
<li class="title">
<span>Documentation documentation documentation documentation documentation documentation</span>
<span>370</span>
</li>
<li class="title">
<span>Documentation</span>
<span>370</span>
</li>
</ul>

Related

text-overflow: ellipsis will not work

I have read all the answers to related questions about text-overflow: ellipsis and regardless of how I have applied what are to be considered the necessary properties, I cannot get it to work without removing it from within the li tags, but it needs to be within the li tags. Any help would be appreciated!
I have tried placing the necessary properties within every element shown, the only place that white-space: nowrap and overflow: hidden have an effect are when they are placed where they are shown here, yet text-overflow: ellipsis has no effect. I have also tried the li element with display: block, but to no avail.
li {
margin-top: 19px;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
img {
display: inline-block;
height: 45px;
width: 45px;
border-radius: 50%;
box-shadow: 0px 1px 5px black;
}
.b {
display: inline-block;
vertical-align: super;
}
.b p {
margin: 5px 5px 5px 15px;
}
.top-text {
font-size: 16px;
color: #65aef8;
}
.bottom-text {
font-size: 16px;
color: #fff;
}
<ul>
<li>
<section class="a">
<img src="img.png" alt="Image">
<section class="b">
<p class="top-text">Text</p>
<p class="bottom-text>More Text</p>
</section>
</section>
</li>
...
</ul>
Changed the CSS on class 'b', element 'p' to this and text-overflow ellipsis worked:
.b p {
margin: 5px 5px 5px 15px;
width: 195px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

Why is that inline-block parent of an no-wrap ellipsis child always seems to take place for complete text?

Please check this example JsBin, here we have simple layout we have a child which have too long text and we need to make it no-wrap ellipsis to avoid breaking of layout but parent seems to occupy the width more then (probably equal to the text) the actual displayed text.
Below is the code
HTML
<div class="title-logo-container" >
<span class="logo">
<a href="/" >
<img src="" alt="LOGO IMAGE">
</a>
</span>
<p class="page-title" s>
test test test test test test test test test test test test test test test
</p>
CSS
.title-logo-container {
border: solid 1px #f00;
display:inline-block;
float:left;
}
.logo {
margin: 1.375em 1.5625em 15px;
padding: 0;
position: relative;
width: 5.625em;
z-index: 103;
display: inline-block;
}
.page-title {
max-width:40%;
display: inline-block;
margin: 0;
font-weight: 400;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
Please suggest.
Expected Output
You're specifying a percentage max-width for an inline-block that is a child of a float that doesn't have an explicit width. This results in undefined behavior because there is a circular dependency between the parent (float) width and the child (inline-block) width.
The apparent browser behavior is that the float is shrink-wrapped to the size of its contents — just enough to contain the content in one line — first, so that it has a size on which the inline-block can then base its 40% max-width. The inline-block then clips its content via overflow: hidden. The size of the float is not computed again.
As BoltClock said, I dont think here inline-block works for this situation, you can try table like this:
Demo
.title-logo-container {
clear: both;
border: solid 1px #f00;
background: green;
display: table-cell;
}
.logo {
margin: 1.375em 1.5625em 15px;
padding: 0;
position: relative;
width: 5.625em;
z-index: 103;
display: table-cell;
background: #ff0;
}
.page-title {
max-width: 40%;
display: table-cell;
font-weight: 400;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
background: #ccc;
}
Hope this helps you !
Check out below solution:
Demo
CSS:
.title-logo-container {
border: solid 1px #f00;
display:inline-block;
float:left;
width:100%;
}
.logo {
margin: 1.375em 1.5625em 15px;
padding: 0;
position: relative;
width: 100px;
z-index: 103;
display: inline-block;
}
.page-title {
width: calc(100% - 160px);
display: inline-block;
margin: 0;
font-weight: 400;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}

Text ellipsis at start of string with CSS?

Getting this effect with CSS it's easy:
This is a very long para...
We just just use text-overflow:ellipsis.
However the reverse
... is a very long paragraph.
seems less obvious.
I have read this comprehensive article but the solution give there is still less than ideal.
Here's the CSS to implement it
.reverse-ellipsis {
text-overflow: clip;
position: relative;
background-color: white;
}
.reverse-ellipsis:before {
content: '\02026';
position: absolute;
z-index: 1;
left: -1em;
background-color: inherit;
padding-left: 1em;
margin-left: 0.5em;
}
.reverse-ellipsis span {
min-width: 100%;
position: relative;
display: inline-block;
float: right;
overflow: visible;
background-color: inherit;
text-indent: 0.5em;
}
.reverse-ellipsis span:before {
content: '';
position: absolute;
display: inline-block;
width: 1em;
height: 1em;
background-color: inherit;
z-index: 200;
left: -.5em;
}
The main problem with it is its length and the fact that the ellipsis looks a bit off.
Does anyone know of a shorter solution that keeps the ellipsis in line?
As per this documentation its possible now🤓. I have added an working example below.
{
direction: rtl;
text-overflow: ellipsis;
}
div {
margin: 5px;
background: #ccc;
padding: 10px;
width: 500px;
}
.box {
line-height: 50px;
border: 1px solid #000;
overflow: hidden;
white-space: nowrap;
font-family: sans-serif;
padding: 0 0.5em;
text-align: left;
}
.el-normal {
text-overflow: ellipsis;
}
.el-reverse {
direction: rtl;
text-overflow: ellipsis;
}
<div>
<h3>Normal</h3>
<p class="box el-normal">
Getting this effect with CSS it's easy: This is a very long para We just just use text-overflow:ellipsis. However the reverse is a very long paragraph. seems less obvious.
</p>
<h3>Reverse</h3>
<p class="box el-reverse">
Getting this effect with CSS it's easy: This is a very long para We just just use text-overflow:ellipsis. However the reverse is a very long paragraph. seems less obvious.
</p>
</div>

How do I display 2 divs on the same line while keeping a horizontal scroll in the last div?

I am attempting to display 2 divs on the same line using css while keeping a horizontal scroll on the last div. So far I have not been able to make this work. I have a jsfiddle, http://jsfiddle.net/fortesl/h54t1t63/3/ , and code shown below:
HTML:
<div class="title-menu">
<div class="title">
A long unbreakable name
</div>
</div>
<div class="toolbar-scroll">
<ul>
<l1>item1</l1>
<l1>item2</l1>
<l1>item3</l1>
<l1>item4</l1>
<l1>item5</l1>
<l1>item6</l1>
<l1>item7</l1>
<l1>item8</l1>
<l1>item9</l1>
<l1>item10</l1>
<l1>item11</l1>
<l1>item12</l1>
<l1>item13</l1>
<l1>item14</l1>
<l1>item15</l1>
</ul>
</div>
CSS:
ul {;
list-style-type: none;
}
li {
display: inline;
}
.title-menu {
display: inline-block;
z-index: 1004;
max-width: 540px;
max-heigth: 40px;
}
.title {
display: inline-block;
font-size: 21pt;
text-shadow: 0 0 1px rgba(40, 40, 41, 0.3);
letter-spacing: 2px;
height: 47px;
overflow: hidden;
white-space: nowrap;
}
.toolbar-scroll {
overflow: scroll;
white-space: nowrap;
overflow-x: scroll;
overflow-y: hidden;
}
I am able to display the divs on the same line by setting 'display: inline-block' on the last div, but doing so disables the scroll bar. I need the scroll bar to work.
Thank you.
Consider the display: table-cell;, it is really pretty handy.
http://jsfiddle.net/h54t1t63/4/
body {
margin-top: 100px;
}
ul {;
list-style-type: none;
}
li {
display: inline;
}
.container { display:table; }
.title-menu {
display:table-cell;
z-index: 1004;
max-width: 540px;
max-heigth: 40px;
}
.title {
display:table-cell;
font-size: 21pt;
text-shadow: 0 0 1px rgba(40, 40, 41, 0.3);
letter-spacing: 2px;
height: 47px;
overflow: hidden;
white-space: nowrap;
}
.toolbar-scroll {
white-space: nowrap;
overflow-x: scroll;
overflow-y: hidden;
height: 3em;
text-align: bottom;
width: 100px;
}
<div class='container'>
<div class="title-menu">
<div class="title">
A long unbreakable name
</div>
</div>
<div class="toolbar-scroll">
<ul>
<l1>item1</l1>
<l1>item2</l1>
<l1>item3</l1>
<l1>item4</l1>
<l1>item5</l1>
<l1>item6</l1>
<l1>item7</l1>
<l1>item8</l1>
<l1>item9</l1>
<l1>item10</l1>
<l1>item11</l1>
<l1>item12</l1>
<l1>item13</l1>
<l1>item14</l1>
<l1>item15</l1>
</ul>
</div></div>
The easiest way is to wrap them into a wrapper div and make it display:table-row while the two divs you want in a single line will have display:table-cell
http://jsfiddle.net/1z5xtd8x/

Icon does not align well with text in Chrome

I'm trying to get the bottom of an icon to line up with some text (to the pixel - the lowest pixel of the first S should be at the same height as the lowest pixel of the foler icon) across browsers, but Chrome is always giving me different results.
Fiddle:
http://jsfiddle.net/LrhB7/1/
HTML:
<div class="study-box set-box">
<div class="set-box-title">
<i class="icon-folder-close-alt">
</i>
<div>SHOULD BE LINED UP WITH BOTTOM OF FOLDER</div>
</div>
</div>
CSS:
.study-box {
width: 200px;
height: 120px;
margin: 2px;
float: left;
color: white;
text-align: center;
font-size: 15px;
position: relative; }
.folder-box-title > div, .set-box-title > div {
-ms-text-overflow: ellipsis !important;
-o-text-overflow: ellipsis !important;
text-overflow: ellipsis !important;
white-space: nowrap;
overflow-x: hidden;
display: inline-block;
text-align: justify;
width: 162px !important;
padding-bottom: 0px;
margin-bottom: 0px;
line-height: 20px;
position: relative; }
.set-box-title {
position: absolute;
bottom: 0;
left: 0;
margin-left: 10px;
padding-bottom: 7px; }
This should be what you're looking for: http://jsfiddle.net/W3WW7/1/
<div class="study-box set-box">
<div class="set-box-title">
<i class="icon icon-folder-close-alt">
</i>
<div>SHOULD BE LINED UP WITH BOTTOM OF FOLDER</div>
</div>
</div>
Changed:
.folder-box-title > div, .set-box-title > div {
-ms-text-overflow: ellipsis !important;
-o-text-overflow: ellipsis !important;
text-overflow: ellipsis !important;
white-space:nowrap;
overflow-x:hidden;
display: inline-block;
text-align: justify;
width: 162px !important;
padding-bottom: 0px;
margin-bottom: 0px;
line-height: 20px;
position: relative;
top: 2px; // changed this line
}
Added:
.icon {
vertical-align: text-bottom;
}