Naor
Naor

Reputation: 24053

create a table using divs only

I have 3 divs and I cannot change the html dom:

<div id="a"/>
<div id="b"/>
<div id="c"/>

I need to create css file that displays those divs like the following table:

<table>
  <tr>
    <td id="a"></td>
    <td rowspan="2" id="c"></td>
  </tr>
  <tr>
    <td id="b"></td>
  </tr>
</table>

Is there any way to do it?

Upvotes: 2

Views: 752

Answers (5)

Clem
Clem

Reputation: 69

What is required in addition to the code above to run these? I copied this into an html document and all I got was 3 rows.

Upvotes: 0

user166560
user166560

Reputation:

Although there's a little extra spacing around the cells on the left, this gives similar presentation to what you're looking for:
demo at jsfiddle

<head>
<style type="text/css">
    #divtable {
        display: table;
        border-collapse: separate;
        border: 1px outset black;
        border-spacing: 2px;
    }
    #d, #e, #f {
        display: table-cell;
        border: 1px inset black;
        padding: 2px;
        vertical-align: middle;
    }

    .row1, .row2 {
        display: table-row;
    }

    .cell_f {
        display: table-cell;
        height: 100%;
    }
</style>
</head>
<body>
<div id="divtable">
    <div class="cell_de">
        <div class="row1">
            <div id="d">D</div>
        </div>
        <div class="row2">
            <div id="e">E</div>
        </div>
    </div>
    <div id="f">F</div>
</div>

Upvotes: 0

Biotox
Biotox

Reputation: 1601

Have the first two divs display:inline-block to keep them on the same line. Make the bottom div the width of the top two plus padding.

Sorry for a bit vague. Example here: http://jsfiddle.net/3ZWGx/4/

--Fixed--

Upvotes: 1

Jacob
Jacob

Reputation: 78850

Assuming that all three divs are surrounded by a container and that these can be rendered at a fixed width, this jsFiddle shows an approach using absolute positioning. Here's the code inline:

Markup (note, that some browsers don't render shortcut divs correctly):

<div id="container">
    <div id="a"></div>
    <div id="b"></div>
    <div id="c"></div>
</div>

CSS:

#container
{
    width: 400px;
    height: 200px;
    position: relative;
}

#a
{
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 100px;
    background-color: red;
}

#b
{
    position: absolute;
    top: 100px;
    left: 0;
    width: 200px;
    height: 100px;
    background-color: green;
}

#c
{
    position: absolute;
    top: 0;
    left: 200px;
    width: 200px;
    height: 200px;
    background-color: blue;
}

Upvotes: 0

lkurylo
lkurylo

Reputation: 1641

Use the css display: http://www.quirksmode.org/css/display.html#table http://www.w3schools.com/cssref/pr_class_display.asp

It works in IE8+.

You have e.g. display:table, table-cell or table-column.

Unfortunatelly, the rowspan is not supported, but you can embed another div in it and emulate it.

Upvotes: 0

Related Questions