1

I'm trying to achieve a responsive Layout with: - A fixed header width width 100% and an height of e.g. 50px - 3 equal squares on the right, taking over the whole space from the top to the bottom of the page. - A main content are taking over the remaining space on the page

Currently my code looks like this (jsfiddle) but I can't get the width of the boxes on the right to be set automatically based on the current height in order to be displayed as squares... Does anybody know a solution for this in pure CSS?

HTML:

        <div id="mainView">
            <div id="content">
            </div><!-- content -->

            <div id="squaressWrapper">
                <div id="square1"></div><!-- dummy -->
                <div id="square2"></div><!-- dummy -->
                <div id="square3"></div><!-- dummy -->
                <div id="square4"></div><!-- dummy -->
            </div><!-- squaressWrapper -->           
        </div><!-- mainView -->
    </div><!-- wrapper -->

CSS: html { height: 100%; margin: 0; padding: 0; }

body {
    height: 100%;
    width: 100%;
    margin: 0px;
    padding: 0px;
}

#wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    display: -webkit-flex;
    flex-direction: column;
    -webkit-flex-direction: column;
    -webkit-align-content: stretch;
    align-content: stretch;
}

#header {
    height: 50px;
    width: 100%;
    background: #ffb8c4;
}

#mainView {
    flex: 1;
    -webkit-flex: 1;
    position: relative;
    background: #666;
}

#squaressWrapper {
    position: absolute;
    height: 100%;
    background: green;
    right: 0;
    display: flex;
    display: -webkit-flex;
    flex-direction: column;
    -webkit-flex-direction: column;
    -webkit-align-content: stretch;
    align-content: stretch;
}

#square1 {
    position: relative;
    flex: 1;
    -webkit-flex: 1;
    width: 100px;
    border: 2px solid white;
    background: green;
}

#square2 {
    position: relative;
    flex: 1;
    -webkit-flex: 1;
    width: 100px;
    border: 2px solid white;
    background: green;
}

#square3 {
    position: relative;
    flex: 1;
    -webkit-flex: 1;
    width: 100px;
    border: 2px solid white;
    background: green;
}
flavordaaave
  • 644
  • 9
  • 21
  • possible duplicate of [Responsively change div size keeping aspect ratio](http://stackoverflow.com/questions/12121090/responsively-change-div-size-keeping-aspect-ratio) – cimmanon Feb 18 '14 at 23:46

2 Answers2

2

I get a solution, using vh units as suggested by Nicho.

The CSS

#squaressWrapper {
    position: absolute;
    height: 100%;
    width: 33vh;
    right: 0;
    display: flex;
    display: -webkit-flex;
    flex-direction: column;
    -webkit-flex-direction: column;
    -webkit-align-content: stretch;
    align-content: stretch;
}

.squares {
    position: relative;
    flex: 1;
    -webkit-flex: 1;
    width: calc(100% - 15px);
    border: 2px solid white;
    background: green;
    right: -11px;
}

demo

The dimensions are a little bit strange because setting the width of the container to calc(33vh - 15px) didn't work.

May be in a near future that will be easier.

I don't know what is the browser support for this, I tested it only in Chrome.

Note : 15px is the dimension of the header (45px) divided by the number of squares.

vals
  • 61,425
  • 11
  • 89
  • 138
-1

Well I took a shot at this... I changed your sizes up on your css

here is the link to the fiddle.

http://jsfiddle.net/D7RSP/2/

#header {
    height: 20%;
    width: 100%;
    background: #ffb8c4;
}

#mainView {
    flex: 1;
    width: 69%;
    height: 100%;
    float: left;
    background: green;

}

.square {        
    flex: 1;
    -webkit-flex: 1;
    width: 30%;
    border: 1px solid white;
    background: green;
    height: 25%;
    float:right;
}
wuno
  • 9,547
  • 19
  • 96
  • 180
  • Thanks for the help but unfortunately this isn't it, yet. The boxes on the right should be squares where the height = width... – flavordaaave Feb 19 '14 at 08:35
  • I am sorry I misunderstood. I played around with it some more. I think the new vh feature might help you. I would really like to understand how to do this as well. If you figure it out please post answer I will do the same. – wuno Feb 19 '14 at 16:34