4

the code is the following:

(CSS)

#container {
    border:1px dashed #000;
    overflow:hidden;
}
#content, #sidebar {
    float:left;
    width:50%;
}
#content {
    background:yellow;
}

#sidebar {
    background:grey;
}

#sidebar {
    height:100%;
}

(HTML)

<div id="container">
    <div id="content">
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
    </div>
    <div id="sidebar">
        <p>Few words</p>
    </div>
</div>

I would like to see a #sidebar div with same height, like the #content div, is it possible without absolute position? Online version: http://jsfiddle.net/yJbUW/

GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
user1452062
  • 805
  • 4
  • 12
  • 27

6 Answers6

8

You can do that by displaying the #container as table and displaying #content and #sidebar as table-cells:

#container {
    border:1px dashed #000;
    display: table;
    width: 100%;
}
#content, #sidebar {
    display: table-cell;
    width:50%;
}

Check your updated Fiddle.

GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
1

You can also try below code

CSS goes here

#container {
    border:1px dashed #000;
    overflow:hidden;
}
#content, #sidebar {
    float:left;
    width:50%;
}
#content {
    background:yellow;
}

#sidebar {
    background:grey;
}


#Container
{
    height: auto;
    width: auto;
}

and update HTML as follows,

<div id="Container">
    <span id="content">
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
    </span>

    <span id="sidebar">
        <p>Few words</p>
    </span>
 </div>
Kishori
  • 1,065
  • 6
  • 12
0

It can be solved with #content, #sidebar { display: table-cell; width:50%; }

8f7ca04d817b1696
  • 644
  • 5
  • 13
0
.table {
    display:table;
}
.row {
    display:table-row;
}
.one {
    width:200px;
    border:1px solid #333;
    display:table-cell
}
<div class="table">
    <div class="row">
        <div class="one">gfhgfhgfhgf</div>
        <div class="one">gfhgfhgfhgf</div>
    </div>
</div>
GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
Bipin Kumar Pal
  • 1,009
  • 2
  • 8
  • 16
0

Just use this code before the container closing Div, works for me!

<p style="clear:both;"></p>
Hashim
  • 1
  • 1
0

Here's the simplest and most elegant solution:

#container {
display:grid;
grid-auto-flow: column;
}