Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent text from expanding shrink wrapped div

Tags:

html

css

width

I have a holder div that's shrink wrapped around a couple other divs, so the holder doesn't have a set width. Also inside the holder is another div that contains text. When there's too much text it's expanding the holder so it's not shrink wrapped anymore. Here's a demo of my problem, http://jsfiddle.net/WSbAt/. This is for a photo gallery page.

I'm thinking there might not be a way without setting the width of the holder, which I can't do since the number of images per row is dynamic. I can probably figure it out with jQuery, but was hoping there's a css solution.

Edit: I'm trying not to specify any widths since the number of thumbnails per row is based on your window size.

Demo: http://jsfiddle.net/WSbAt/

CSS:

#container
{
    width:600px; /*only set for demo. will be random on live page*/
    border:1px solid black;
    text-align:center;
}
#holder
{
    display: inline-block;
    border:2px solid blue;
}
.thumbnail
{
    float:left;
    width:100px;
    height:100px;
    background-color:red;
    margin-right:10px;
    margin-bottom:10px;
}
.expandedHolder
{
    padding:10px;
    border:2px solid yellow;
    margin-bottom:10px;
    margin-right:10px;
}
.fullImage
{
    float:left;
    width:250px;/*only set for demo. will be random on live page*/
    height:200px;
    background-color:green;
}
.text
{
    float:left;
    margin-left:10px;
}

HTML:

<div id="container">
    <div id="holder">
        <div class="thumbnail"></div>
        <div class="thumbnail"></div>
        <div class="thumbnail"></div>
        <div class="thumbnail"></div>
        <div style="clear:both;"></div>
        <div class="expandedHolder">
            <div class="fullImage"></div>
            <div class="text">some text here. some text here. some text here. </div>
            <div style="clear:both;"></div>
        </div>
        <div style="clear:both;"></div>
    </div>
</div>
like image 739
JoJo Avatar asked Apr 26 '13 13:04

JoJo


1 Answers

Use a percentage as width for .fullImage and .text

        .fullImage
        {
            float:left;
            width:70%;
            height:200px;
            background-color:green;
        }
        .text
        {
            width: auto;
            float:left;
            width:20%;
            margin-left:10px;
        }

Then if the text gets to large use text-overflow

text-overflow:ellipsis; 

or overflow

overflow:hidden;


http://jsfiddle.net/RubenJonker/WSbAt/5/

like image 162
Ruben-J Avatar answered Sep 26 '22 11:09

Ruben-J