Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3 Divs, 2 Fixed width and 1 Fluid

Tags:

html

css

I have a problem, where i am floating the first div(30px width) to the left, the third div(30px width) to the right and havin the second div take up the remaining space from the entire window width

Example:

http://jsfiddle.net/AScBN/188/

.right
{
   height:40px;
   width:40px;
   float:left;
   background:green;
}

.left
{
   height:40px;
   width:40px;
   float:right;
   background:green;
}

.fluid
{
   margin-right: 50px;
   height:40px;
   background:red;
}

div
{
   border:1px solid yellow;
}

Problem:

I cant get them to sit beside each other, the last div gets pushed under obviously because of the fluid second div

Thanks

Aiden

like image 569
Aiden Avatar asked Aug 26 '13 03:08

Aiden


People also ask

Can you have 3 divs side by side?

Three or more different div can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side.

How do you give a div a fixed width?

Use a the clearer div to force the main section to extend its height when the content div expands. At this point, you have a fluid-width layout. To convert it to a fixed-width layout, simply add a fixed with to the #wrapper and set the margins to auto.

How do I make DIVS stay the same size?

if you set width:500px; and height:300px; (or whatever size you want) the div should stay the same size. Also, you can set overflow:hidden; so that if whatever is in the div goes beyond those bounds, it is not shown, and does not resize the div. Save this answer.

Why is my div overflowing?

Overflow happens when there is too much content to fit in a box. CSS provides various tools to manage overflow. As you go further with CSS layout and writing CSS, you will encounter more overflow situations.


2 Answers

you got the orders wrong

<div class="right">1</div>
<div class="left">3</div>
<div class="fluid">3</div>

the non-floating div should be the last one.

like image 82
ragnika Avatar answered Oct 13 '22 20:10

ragnika


Here's another incredibly easy way to do this using Flex - updated jsFiddle

HTML

<div class="wrapper">
    <div class="fixed">1. Fixed Right</div>
    <div class="fluid">2. Fluid</div>
    <div class="fixed">3. Fixed Left</div>
</div>

CSS

.wrapper {
    height:40px;
    display: flex;
    flex-flow: row wrap;
    justify-content: space-around;
}
.wrapper div {
    margin: auto;
    border:1px solid yellow;
    height: 40px;
    text-align: center;
}
.fixed {
    width:40px;
    background:green;
}
.fluid {
    flex: 1;
    background:red;
}
like image 1
Pixel Rubble Avatar answered Oct 13 '22 19:10

Pixel Rubble