5

I've been trying for 3 days to avoid using table in my new responsive design, mostly because everyone says they are evil. On the other hand while doing more research on SEO and table, some people even say it improves their visibility.

In any case, the semantic is much nicer with divs and HTML5, so I would really like to have this following example working. The main problem is that in IE9 & 10, the "section row" will overflow because of the 'height 100%' value. All other browsers seems to be reacting fine.

Does anyone know how to solve this (ideally without Javascript?) :

JSFiddle: http://jsfiddle.net/fvqvdske/1/

Fullsize page to test in IE10 emulation mode: http://jsfiddle.net/fvqvdske/1/show

The only problem is the overflow and IE9, 10 - the middle row needs to fill all the space left by the header and footer (and the header and footer needs to be able to adjust height to fit their content dynamically e.g. no fixed, no absolute positions).

HTML

<body>
<header role="banner">
    <div>
        <div>
            This is the top banner
        </div>
    </div>
</header>
<section role="main">
    <div>
        <div>
            <div>
               <div>
                   <div style="border: 2px solid red;">
                        This is the content<br/>
                        This is the content<br/>
                        This is the content<br/>
                        This is the content<br/>
                        This is the content<br/>
                   </div>
                </div>
            </div>
        </div>
    </div>
</section>
<footer role="contentinfo">
    <div>
        <div>
            This is the footer
        </div>
    </div>
</footer>
</body>

CSS

    html, body {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
    }
    body {
        height: 100%;
        width: 100%;
        display: table;
        position: absolute;
        border-spacing: 0;
        border-collapse: collapse;
    }

    header, footer, section {
        display: table-row;
        text-align: center;
        vertical-align: middle;
        height: 1px;
    }

    header > div, section > div, footer > div {
        display: table-cell;
        vertical-align: middle;
    }

    header > div > div,
    section > div > div,
    section > div > div > div,
    footer > div > div {
        max-width: 400px;
        width: 100%;
        margin: auto;
        background-color: brown;
    }

    section,
    section > div,
    section > div > div,
    section > div > div > div,
    section > div > div > div > div {
        box-shadow: inset 0 1em 1em -1em #222, inset 0 -1em 1em -1em #222;
        height: 100%;
        vertical-align: middle;
    }

    section > div {
        display: table-cell;
        width: 100%;
        height: 100%;
    }

    section > div > div {
        display: table;
        margin: auto;
    }

    section > div > div > div {
        display: table-row;
    }

    section > div > div > div > div {
        display: table-cell;
    }


    section {
    }

    /* temp */
    header {
        background-color: pink;
    }

    section {
        background-color: yellow;
    }

    footer {
        background-color: orange;
    }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Nicolas Bouvrette
  • 4,295
  • 1
  • 39
  • 53
  • Its an ugly bug, have you tried using flex box? `display: flex;` http://jsfiddle.net/GXe9m/2/ – jagmitg Aug 31 '14 at 11:59
  • 1
    Flexbox is not supported enough for my project: http://caniuse.com/#search=flexbox - Are you sure this is a bug.. nothing we can do to work around it? I did a minor update to clean my css and make it a bit easier to follow. – Nicolas Bouvrette Aug 31 '14 at 12:00
  • Personally, If I had to use display:table, table-row and table-cell, then I would use actual HTML tables. Seems confusing to me. Never heard of the SEO argument. Do you have a link with more info on that? – 700 Software Aug 31 '14 at 12:01
  • @nbouvrette try setting a `max-height:100%;` as well as the `height: 100%;` Does it make a difference? – jagmitg Aug 31 '14 at 12:03
  • Here is the SEO link: http://webmasters.stackexchange.com/questions/6890/are-html-tables-bad-for-seo - Also the only reason I use tables is because of the middle section. I want it to fill 100% of the height when there is not enough content. I got 2 other threads going about fixing this without tables and no one could figure it out. I have a table layout working perfectly fine as well but semantically this one is simpler (but as you said maybe less straight forward to understand). – Nicolas Bouvrette Aug 31 '14 at 12:04
  • max-height:100% makes no difference - I tried it already :) this bug seems to be as old a IE8 too... IE11 has it fixed. – Nicolas Bouvrette Aug 31 '14 at 12:05
  • I can't test it right now, but did you already test it by not using `body` with `display: table` but an additional elements. I know that I had some problems when experimenting with the `display` type of `head`, `body` and `title` elements in IE. But to be honest I don't know anymore what exact problem has been. – t.niese Aug 31 '14 at 12:43
  • @nbouvrette from your link the majority of answers say: no impact or bad impact of using tables instead of divs. – Claudiu Creanga Aug 31 '14 at 12:46
  • Yes Im pretty sure I tested it but I will confirm as soon as Im back at my computer. Unless anyone else can give it a shot in the meantime? :) – Nicolas Bouvrette Aug 31 '14 at 12:47
  • @Claudiu the impact is not clear.. what Im more worried about is the semantics and how search engine will deal with table in the future. Also lets say tables are not very trendy... Im worried about their future support in browser as well but maybe that's overthinking – Nicolas Bouvrette Aug 31 '14 at 12:48
  • [This answer is relevant](http://stackoverflow.com/a/84986/2930477) to you! – misterManSam Aug 31 '14 at 12:56
  • tables are here to stay forever to display tabular data – Claudiu Creanga Aug 31 '14 at 12:58
  • @Claudiu so thats my point.. using it for layout in 2014 is looking for trouble no? – Nicolas Bouvrette Aug 31 '14 at 12:59
  • @misterManSam thanks I found his one already.. problem is for my situation I would only use a single table... but it would nest all my content. I just want to make sure that using this approach make sense since I was able to get divs and CSS working for this scenario – Nicolas Bouvrette Aug 31 '14 at 13:02

1 Answers1

2

After spending a few days on this question, it seems that for this specific layout (especially the 100% height), using tables is the best option. Those 3 different threads with different twist of the question were unable to get results (so I suspect that this IE bug is one reason to keep using tables in 2014):

By reading more about tables and SEO, I was also unable to find any relevant information or tangible data that using a single table would have any impact at all. The only tangible information I was able to find is that tables will only display once the full HTML has been downloaded in the client. Which again is not a big issue in 2014 considering the HTML's size in the overall size of a web page. CSS can be used for all of the table's style which solves some of the other complains I saw about tables. This article probably reflects best the situation here:

http://olav.dk/articles/tables.html

Tables in 2014 might be ok :)

Community
  • 1
  • 1
Nicolas Bouvrette
  • 4,295
  • 1
  • 39
  • 53
  • 4
    Whenever you use `table` for layout you should marke it using `role="presentation"` [W3C: 4.9.1 The table element](http://www.w3.org/TR/html5/tabular-data.html#the-table-element): `[...]Tables should not be used as layout aids.[...] If a table is to be used for layout it must be marked with the attribute role="presentation"[...]` As a border value other then `1` or _empty_ is not valid for html5 you should not use `border=0` to indicate that. – t.niese Sep 01 '14 at 05:07
  • @t.niese Good catch! I just added this to my code. Thanks – Nicolas Bouvrette Sep 01 '14 at 13:10