Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tricky HTML layout

Tags:

html

css

Can anyone think of a way to approach converting the following scheme into a non-table html layout?

enter image description here

A few things worth mentioning, perhaps.

  • Only the central block is mandatory (and should turn into a normal square block if it is the only one there).
  • The total number of blocks is unpredictable, so layout should be easily expandable (and hence non-table).
  • Exact left alignment of the text in all blocks is not crucial.
  • No gaps other than shown are allowed
  • Gray background can be semi-transparent, so no overlap is allowed too.

Thanks in advance!

like image 342
Dennis Kreminsky Avatar asked Feb 13 '11 13:02

Dennis Kreminsky


1 Answers

Ok.. it's VERY hard :) ..btw, if the text inside of it is 'static', you could do some tricks with floats and negative margins this way:

http://www.jsfiddle.net/steweb/Xa5X6/

I know it's not the best result, but it could be a way to start with :)

markup:

<div class="wrapper">
    <div class="column">
        <div id="sq-1"></div>
        <div id="rect-1"></div>
    </div>
    <div class="column">
        <div id="sq-2"></div>
        <div id="rect-2"></div>
    </div>
    <div class="column main">
        <div class="text-container-1">
            <div class="text-1">
                text 
            </div>
            <div class="text-2">
                text 
            </div>
        </div>
        <div class="text-3">text </div>
        <div class="text-4">text</div>
        <div class="text-5">text</div>
    </div>
</div>

css:

.wrapper{
    overflow:hidden;
    background:#777;
    display:inline-block;
}
.column{
    float:left;
}
#sq-1{
    width:20px;
    height:21px;
}
#sq-2{
    width:20px;
    height:21px;
    margin-top:20px;
    border-top:2px solid #FFFFFF;
}
#rect-1{
    height:104px;
    border-right:2px solid #FFFFFF;
}
#rect-2{
    height:82px;
    border-right:2px solid #FFFFFF;
}

.text-container-1{
    width:200px;
    border-right:2px solid #FFFFFF;
}
.text-1, .text-2{
    border-bottom:2px solid #FFFFFF;
}
.text-3{
    float:left;
    width:220px;
    margin-top:-44px;
    padding-top:54px;
    padding-bottom:10px;
    border-bottom:2px solid #FFFFFF;
    border-right:2px solid #FFFFFF;
}
.text-4{
    float:left;
    width:240px;
    margin-left:-222px;
    margin-top:-44px;
    padding-top:84px;
    border-bottom:2px solid #FFFFFF;
    border-right:2px solid #FFFFFF;
}
.text-5{
    float:left;
    width:260px;
    margin-left:-242px;
    margin-top:-44px;
    padding-top:104px;
    border-bottom:2px solid #FFFFFF;
    border-right:2px solid #FFFFFF;
}

In this example, you have to assign static heights to the elements on the left. Moreover, the negative margins of the elements on the right are static too.

static text => static dimensions/margins => a kind of weird result

If the text is dynamic, I think achieving a result without using JS and/or tables is almost impossible, also because these 'L' elements and theirs widths/heights are hard to manage.

dynamic text => swearing

like image 140
stecb Avatar answered Oct 17 '22 18:10

stecb