0

It's quite a simple question but I can't figure out what's wrong.

I have three divs, 2 of set pixel sizes and the other (the middle) fills the remaining space between the two.

|------|--------------------------|------|
|      |                          |      |
|      |                          |      |
|      |                          |      |
|------|--------------------------|------|
       <-------------------------->
                 Width Fill

I have the following CSS:

Left Div

#leftdiv {
    height: 50px
    width: 50px;
    float: left;
    }

Middle Div

#middlediv {
    min-width: 270px;
    width: calc(100% - 100px);
    width: -moz-calc(100% - 100px);
    width: -webkit-calc(100% - 100px);
    width: -o-calc(100% - 100px);
    float: left;
}

Right Div

#rightdiv {
    width: 100px;
    height: 50px;
    float: right;
}

I've simplified it here, but basically the right div doesn't actually float, it goes underneath like so:

|------|--------------------------|
|      |                          |
|      |                          |     
|      |                          |      
|------|--------------------------|
                                |------|
                                |      |
                                |      |
                                |      |
                                |------|
DorianHuxley
  • 622
  • 3
  • 10
  • 22

3 Answers3

0

clear:both makes the element drop below any floated elements that precede it in the document.

so try using clear: both in #rightdiv.

For more information, check this SO Answer.

Community
  • 1
  • 1
Praveen
  • 53,079
  • 32
  • 129
  • 156
0
#middlediv {
    min-width: 270px;
    width: calc(100% - 150px);
    width: -moz-calc(100% - 150px);
    width: -webkit-calc(100% - 150px);
    width: -o-calc(100% - 150px);
    float: left;
}

The sum of the widths of your div is exceeding the width of the screen, so the right div is pushed down

Gangadhar
  • 1,661
  • 15
  • 19
0

Your #rightDiv has a width of 100px when it needs to have a width of 50px

#rightdiv {
    width: 50px;
    height: 50px;
    float: right;
}

Otherwise the combined width of the left and right divs is 150px and you are only subtracting 100px

width: calc(100% - 100px); //100px is too small
Pattle
  • 6,653
  • 7
  • 30
  • 54