Unholy Grail Layout (Reverse Holy Grail Layout)

1

The Holy Grail Layout in CSS, is a full height, 3 column layout which consists of a fluid central column, and two side columns with fixed widths.

Your Task is Simple!

Reverse it, make a fixed width central column, and two fluid width columns to the sides. The point is for them to take All available space both vertically and horizontally. So if one adds elements above, or elements below (assume 100% width), your solution should shrink to accommodate. Same goes with elements on the sides. Your layout should fill 100% of its container's space.

Restrictions

  • HTML and CSS only (no JavaScript)
  • IE8+ support mandatory
  • Must work in all major browsers (it is, after all, a layout!)
  • HTML and CSS must both be valid.
  • No tables, it's supposed to be a layout, not an abomination.

Winner

  • Code with fewest characters wins, excess spaces and newlines do not count, don't be afraid to be readable! (I'm running the solution through a minifier)

Good luck!

Madara's Ghost

Posted 2013-09-07T20:48:33.070

Reputation: 119

2

The specification is a bit vague, but on the assumption that it can be tightened up, how would you pick a winner between two solutions? All questions on this site should have an objective primary winning criterion.

– Peter Taylor – 2013-09-07T22:06:05.013

Well, with the lack of a better criterion, I'd say it would be shortest code possible. I'll edit it as soon as I get to a PC. – Madara's Ghost – 2013-09-08T04:31:38.797

How about providing a list of browsers to support, then score by the following? [code size] / [number of actually supported browsers] – Hand-E-Food – 2013-09-08T22:15:29.303

1I think the current attempt at an answer validates my comment that the specification is a bit vague. Can you give a precise definition of what counts as a "column"? – Peter Taylor – 2013-09-09T08:46:44.667

@PeterTaylor As always: Proof by example. I don't know yet if this is counter productive or not. – Johannes Kuhn – 2013-09-09T08:53:02.340

I will update the criteria when I get to a PC later today. – Madara's Ghost – 2013-09-09T10:19:50.240

Edited to make clear (tell me if you still need more information). Sorry for those whose solutions were invalidated. (My first puzzle on this site :D) – Madara's Ghost – 2013-09-09T15:15:16.003

Answers

2

Simple

<div style=float:left;>L</div><div style=float:right;>R</div><div style="width: 100px;margin:0px auto;">C</div>
  • Who said that it needs to be valid html?
  • Who said that I need a doctype?

Johannes Kuhn

Posted 2013-09-07T20:48:33.070

Reputation: 7 122

0

Guaranteed to work in all browsers - old and new:

<table>
<tr>
    <td>a</td>
    <td class="f">b</td>
    <td>c</td>
</tr>
</table>

CSS:

table, tr{
    width: 100%;
}
.f{
    width:100px;
}

Here's a fiddle: http://jsfiddle.net/8QWBX/1/

Note: if you want to make it shorter (but fail HTML standards) you may remove the tr tag and its styling. This will save 12 characters the way I see it.

Dzhuneyt

Posted 2013-09-07T20:48:33.070

Reputation: 231

4Table for layout? I feel ill. – Gareth – 2013-09-09T13:10:10.690

0

display:table-cell is compatible ie8+ (as seen in caniuse)

<!DOCTYPE html>
<head>
  <title>a</title>
  <style>
    html { height: 100%}
    body { margin: 0; display: table; height: 100%; width: 100%}
    .c { display: table-cell }
    .c2 { width: 6em }
  </style>
</head>

<a class="c c1">a</a>
<a class="c c2">z</a>
<a class="c c3">e</a>

This is html/css valid, tried here : https://validator.w3.org/nu/#textarea

That's why there is head/title stuff. But you can ommit html/body, according to the specs.

The issue I see is when you want to put something above/below, you have to make them display: table-row, and probably specify a height.

long-lazuli

Posted 2013-09-07T20:48:33.070

Reputation: 121

2Why the downvotes ? Based on (not so clear) requirements, this answer is quite acceptable – sodawillow – 2015-11-13T08:18:09.623