tags:

views:

40

answers:

1

I have a line of text that I want to draw borders around. At the moment, the markup looks like this:

<div id="titleBox"><span id="titleName" class="truncate">Really really long long long title name</span></div>

The style looks like this:

    #titleBox{
    margin-top: 10px;

}

#titleName{
    margin: 5px;
    height: 1.6em;
    width: auto;
    max-width: 15.385em;    
    padding: 0.369em;
    margin: 0.369em;
    line-height: 1.7;
    color: rgba(0,0,0,0.4); 
    background-color: rgba(204,204,204,0.4); 
    border: 3px solid rgba(255,255,255,0.14);
    font-size: 153.9%;
    -moz-border-radius: 5px; 
    -webkit-border-radius: 5px;     
}

.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -ms-text-overflow: ellipsis;        
    -o-text-overflow: ellipsis;
    -moz-binding: url('../templates/ellipsis.xml#ellipsis');
}

The effect that I'd like is that I'd like the styled box to be the width of the text, unless the width exceeds a certain limit. Then I would want the width to be limited and then the truncate class should kick in.

The problem with only using a div is that the box doesn't wrap to the width of the text. Using a span helps but then it doesn't display as a block. Forcing it to display as a block exhibits the same problem as wrapping it in a plain div. Using a div/span combination doesn't work either because the span ignores the boundaries of the div if the text is too long.

Is there a way to limit the width of the text, forcing it to truncate and have a styled box surrounding the text?

A: 

As per my comment, display:inline-block should give the desired effect. it won't work in <IE6 though.

Andy E