Ender Özcan
Ender Özcan

Reputation: 69

This layout can be done with CSS?

Is it possible to do the following layout with CSS but not using absolute/relative positioning?
We tried to solve this riddle for several days but we couldn't fit the box 10.

Please also provide css + html files of your solution. So we can discuss solutions.

is it possible?

Upvotes: 4

Views: 481

Answers (6)

user94893
user94893

Reputation:

I just solved this problem by using this source code.

alt text http://rabu4g.bay.livefilestore.com/y1p4IhbA7NzQWn7G3wY8dkhOEGawswOMPZQ8MXUotkWtx9ppwfcILzwVb3xXKL19d1J-U5d6G7jaftIHjdcwU8_fTFYyJWtaj6t/css.png

Update

Can you explain how browser renders floating item?

PS. My main techniques are negative left-margin & grouping div. It's single way to solve this problem without using relative and absolute position.

Upvotes: 8

Daniel Sloof
Daniel Sloof

Reputation: 12706

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <link rel="stylesheet" type="text/css" href="css/reset.css" />
        <style type="text/css">
            div#container { width: 500px; height: 143px; }
            div#container div { float: left; text-align: center; color: #ffffff; }
            div#t01 { width: 85px;  height: 85px;  background-color: #ee4727; }
            div#t02 { width: 138px; height: 49px;  background-color: #cab6c2; }
            div#t03 { width: 160px; height: 35px;  background-color: #d7446e; }
            div#t04 { width: 113px; height: 27px;  background-color: #2cda54; }
            div#t05 { width: 159px; height: 51px;  background-color: #e1abcf; clear: left; }
            div#t06 { width: 111px; height: 87px;  background-color: #5de1b0; margin-top: -36px; }
            div#t07 { width: 62px;  height: 101px; background-color: #323fbf; margin-top: -50px; }
            div#t08 { width: 120px; height: 77px;  background-color: #234457; margin-top: -50px; }
            div#t09 { width: 44px;  height: 85px;  background-color: #1f5a82; margin-top: -58px; }
            div#t10 { width: 164px; height: 24px;  background-color: #eb2cf4; }
        </style>
        <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
    </head>
    <body>
        <div id="container">
            <div id="t01">T01</div>
            <div id="t02">T02</div>
            <div id="t03">T03</div>
            <div id="t04">T04</div>
            <div id="t05">T05</div>
            <div id="t06">T06</div>
            <div id="t07">T07</div>
            <div id="t08">T08</div>
            <div id="t09">T09</div>
            <div id="t10">T10</div>
        </div>
    </body>
</html>

Works in IE8, FF2, FF3, Chrome, Safari, Opera. Doesn't work in IE6 and IE7 for unknown reasons to me.

(widths and margins may be a little off, image was low qual and I just used magic wand tool in photoshop)

Upvotes: 0

Mete Karabicak
Mete Karabicak

Reputation:

My solution:

<style type="text/css">

div { width:524px; height:142px; }
div div { float:left; color:white; text-align:center;}

#objX01  {  background:#ed4728; width:91px;height:90px; }
#objX02  {  background:#c9b7c3; width:145px;height:50px; }
#objX03  {  background:#d7446d; width:168px;height:37px; }
#objX04  {  background:#2cdb54; width:120px;height:29px; float: right;}
#objX09  {  background:#1e5a82; width:47px;height:90px; float: right;}
#objX08  {  background:#224456; width:128px;height:82px; float: right;}
#objX07  {  background:#3240c0; width:64px;height:105px; float: right;}
#objX06  {  background:#5ee1b1; width:118px;height:92px; float: right;}
#objX05  {  background:#e0abce; width:167px;height:52px; }
#objX10  {  background:#ec2df6; width:175px;height:23px; float: right;}
</style>

<div style="position:relative; margin:0 auto">
  <div id="objX01">01</div>
  <div id="objX02">02</div>
  <div id="objX03">03</div>
  <div id="objX04">04</div>
  <div id="objX09">09</div>
  <div id="objX08">08</div>
  <div id="objX07">07</div>
  <div id="objX06">06</div>
  <div id="objX05">05</div>
  <div id="objX10" style="position:absolute; left:349px; top:119px">10</div>
</div>

Upvotes: 0

HyLian
HyLian

Reputation: 5093

As a starting point you can use Photoshop or another software to define the regions and generate the HTML+CSS.

The code generated isn't very clean but it would be a good base to begin making changes.

Upvotes: 0

Bob Somers
Bob Somers

Reputation: 7306

All of it should be doable. As Jim Neath mentioned, you can do boxes 1-9 with float left's, clears, and negative top margins.

For Box 10, you could float it left so that it would normally appear to the right of box 9, but apply a negative left margin to push it over next to 7 (based on the width of 8 and 9).

Upvotes: 0

Jim Neath
Jim Neath

Reputation: 1217

You could try float:left all the boxes. Then give boxes 6-9 a negative top margin. And clear:left box 5.

Not entirely sure if that would work, but it's worth a try.

Upvotes: 2

Related Questions