Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS shrink container to size of two dynamic width divs

Tags:

html

css

This is what I'm trying to achieve

                            CONTAINER
 --------------------------------------------------------------
|                      CENTERED in CONTAINER                   |
|    -----------------------------------------   ----------    |
|   | Content Div                             | | Info Div |   |
|   | shrink to contents  OR                  | | shrink to|   |
|   | max size: (container width - info div ) | | contents |   |
|   |                                         |  ----------    |
|    -----------------------------------------                 |
|                                                              |
|    ------------------------------------------------------    |
|   |  text div: width = width of content div + info div   |   |
|    ------------------------------------------------------    |
 --------------------------------------------------------------

PICTURES (crude MSPAINT): small content example and large content example

DIV INFO: Max 192 pixels, but should shrink if necessary.

DIV CONTENT: Shrink to content. If content is large, width= remaining space in container.

DIV TEXT: width = width of CONTENT + width of INFO.

Here's what I have so far. I am not using floats because I want the content and info divs to be overall centered on the page.

The problems I am having are:

  • the text div expands to the container size.
  • if the browser window is shrunk, the info div gets bumped to the next line.

CSS

#container {
    width: 80%;
    min-width: 760px;
    padding-top: 0;
    margin: 0 auto; 
}
#content {
    max-width: 71%; /* Kinda solves the problem of bumping info div
                       to next line, but leave awkward gaps */
    width: auto;
    vertical-align: top;
    display: inline-block;
}
#info {
    width: auto;
    vertical-align: top;
    text-align: left;
    display: inline-block;
}
#text {
    margin: 10px auto;
    width: auto;
    display: block;
    text-align: left;
}

HTML

<div id="container">
<div id="main">
    <div id="content"><img src="image.jpg" />Lorem ipsum ...</div>
    <div id="info">Lorem ipsum dolor</div>
    <div id="text">Lorem ipsum ...</div>
</div>
</div>
like image 417
encore2097 Avatar asked Feb 12 '11 22:02

encore2097


3 Answers

Try this: http://jsfiddle.net/JbuBC/2/ http://jsfiddle.net/JbuBC/14/

like image 105
Shaz Avatar answered Sep 19 '22 03:09

Shaz


Add float:left; to #info and #content

Remove max-width: 71%; from #content

HTML code would be a good help if you have some?

Demo

like image 44
Myles Gray Avatar answered Sep 19 '22 03:09

Myles Gray


To make #text width equals to Content+Info width you need to wrap #content, #info, #text with one more div.

like image 23
user194076 Avatar answered Sep 21 '22 03:09

user194076