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
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.
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.
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.
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.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With