Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I have created a css table layout with display:table and so on, but when it shows up in browser the height of the cells/row seems not correct.

Have a look here:
http://jsfiddle.net/ev092xoq/[^]

For my understanding the height of the red and green area should be the same as the white one...

Can anyone explain why thats not the case??


Please be aware that I don't try to make a 3 column design but the white area should remain inside the red area.


Greetings
Posted
Updated 15-Jan-15 22:08pm
v2

Fiddle Update[^]

First of all I would like you to remove all the inline styles and add class use css instead. That makes code more readable and easy to maintain.

I have updated the fiddle by you. Please check.
Post back queries if any.
Thanks.
 
Share this answer
 
Comments
exoc 16-Jan-15 5:04am    
First of all you're right (regarding your tip about css).

Sadly, your solution does not work on IE.

And, I don't get it... what is the table-caption tag for?

Is there a solution that remains the table-cell tag?
Weird stuff is going on in the css somewhere on the browser parsing.
I can not explain why it is doing what it is doing, maybe someone else has a clue on that one.

But here is an alternative method to get your desired effect using display:inline-block;
HTML
<div class="init" style="width: 100%; height: 8em; overflow: hidden; background-color: gray;">
    <h3>Using inline-block:</h3>
    <div style="display:inline-block;">
        <div style="display:block;height: 2em;">
            <div style="display:inline-block;width: 4em; overflow: hidden; background-color: green;">
                <div style="height: 2em; overflow: hidden; max-height: 2em;">
                    <span>links </span>
                </div>
            </div><div style="display:inline-block;width: 8em; overflow: hidden; background-color: red;">
                <div style="height: 2em; overflow: hidden; max-height: 2em;">
                    <div style="width: 2em; height: 2em; background-color: white;">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Here is link to your fiddle updated: http://jsfiddle.net/ev092xoq/4/[^]
In your version: borders added to all divs and an additional table equivalent.
It can be seen the div-td-cells are taking more height than they should do (if compared the table equivalent).

--Solution revisited--
Add some text or &nbsp; to the White div and it works:
HTML
<div style="width: 2em; height: 2em; background-color: white;">text or something needs to be added here</div>

Updated fiddle: http://jsfiddle.net/ev092xoq/6/[^]
 
Share this answer
 
v2
Comments
exoc 16-Jan-15 7:49am    
Thanks man for your hard work!
But I need the functionality of the css table attribute, because I need to be able to stretch the cell sometimes.
jaket-cp 16-Jan-15 8:01am    
What do you mean by stretch the cell?
Scrap that, I had another look at updated fiddle and got it to work.
Will update solution.
jaket-cp 16-Jan-15 8:10am    
solution updated - have a look :)
exoc 19-Jan-15 3:49am    
I really appreciate your effort. Thank you very much.

The problem that I see is that what makes your example work is the character (white-space) inside the white div. Remove it and it looks ugly as before :-(

This means your right; you fixed it!
But also it is not usable for me (in the bigger context of my approach).

Thanks again anyway
jaket-cp 19-Jan-15 5:21am    
Not a problem.
I have also noticed when the links text is removed it also works.
So if text in both will work and no text in both will also work.
But will not work if text in one and not the other.
This appears to be happening in FF and Chrome, where in IE the span element is taken into consideration somehow.
As I have said I am not sure what is happening in the browser parsing side of things, but at a guess it may have something to do with what happens to empty td (when empty border not displayed) and the div are inheriting the characteristics of their parents and their parent(s) are pretending to be a td and it is missing something.

Also can you not use the table markup to do what you require?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900