0

here is some sample code http://jsfiddle.net/XpLSZ/2/

<div class="main">
    <div class="item ">
        <img class ="icon" src="https://www.google.com/s2/favicons?domain=http://planet.clojure.in"/>
        <span class="title" >This is a test Long title</span>
        <span class="count" >(22)</span>
    </div>
</div>

.main{
   border-style: solid;
    border-width: medium;
    width:200px;
}
.icon{
    width:12px;
    height:12px;
}
.truncate {
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

What I want is to have a row with icon.title and count and have the title truncate instead of wrapping, is this possible with css ? (I do not want count to be truncated) Now I do some truncation in JS but the problem is that layout is different in some browsers and also it brakes on some zoom levels.

Danield
  • 121,619
  • 37
  • 226
  • 255
simion314
  • 1,394
  • 16
  • 29

1 Answers1

2

1) Update your markup so that count element is before the title.

2) float the count element right

FIDDLE

<div class="main">
    <div class="item truncate">
        <span class="count">(22)</span>
        <img class="icon" src="https://www.google.com/s2/favicons?domain=http://planet.clojure.in" /> 
        <span class="title ">This is a test Long title </span>
    </div>
</div>

CSS

.count {
    float:right;
}

UPDATE:

Well it seems that FF doesn't like floating the count element, instead we can absolutely position the count element to the right, and leave space for it in the parent.

Like so:

FIDDLE

.item {
    padding-right:25px;
    -moz-box-sizing: border-box;
    box-sizing: border-box; 
    position:relative;
}

.count {
    position:absolute;
    right:0;
}
Danield
  • 121,619
  • 37
  • 226
  • 255
  • Thanks,It is working fine on Chrome, in Firefox there is a overlap(I can see a l under the count text http://i.imgur.com/SGBURtD.png ,do you have a workaround for this FF issue? – simion314 Jun 24 '14 at 14:20
  • @simion314 - I updated my answer which works on webkit, firefox and IE (just verified this) – Danield Jun 24 '14 at 14:37