I am trying to arrange 3 divs side by using float:left, there is fixed height for two div's child1 and child3, but there is no height for child2, i need the child2 div height as the same height of the container div.
<div id="container">
<div id="child1">Child1</div>
<div id="child2">Child2</div>
<div id="child3">Child3</div>
<div>
#container
{
margin-left: 3px;
padding: 10px 0px;
position: relative;
display: block;
width: 500px;
background:yellow;
overflow:hidden;
}
#child1
{
float:left;
width:100px;
height:300px;
background:green;
}
#child2
{
float:left;
width:100px;
height:auto;
background:cyan;
}
#child3
{
float:left;
width:100px;
height:400px;
background:red;
}
here is the fiddle: http://jsfiddle.net/2ksxL/2/
You can change the #container {display: flex;}, but that does not have awesome support in IE (http://caniuse.com/flexbox). If you need more support you will have to come up with a jQuery solution that can find the height of the container and give it to #child2.
Since you haven't define any height for container, the container height is going to depend on the max height that's been defined to the #childX. In this case, #child3. So what you can do is compare the height of both #chidl1 and #child3 and set the height of #child2 to the max one via this little jQuery.
var highestCol = Math.max($('#child1').height(),$('#child3').height());
$('#child2').height(highestCol);
FIDDLE
Related
When I try to set height: 100% on a child div, the height stays 0.
This is the parent div:
#game-content {
margin-top: 50px;
overflow: auto;
height: 100%;
width: 100%;
}
#game-wrapper {
float: left;
margin-left: 90px;
position: relative;
height: 100%;
}
<div id="game-content">
<div id="game-wrapper">
<div class="game">
<img class="game-element" src="http://placehold.it/200x200" />
<div class="game-element" id="description">
<h4 id="game-header">Game1</h4>
Desc
</div>
</div>
</div>
</div>
The height of game-content is also 100% (it's not 0). Although the height of game-wrapper stays 0, while the width does work. What am I doing wrong?
the #game-content or its parent(body) must have a fixed height, if try setting a fixed height in #game-content the #game-wrapper will have its 100% height.
Try out:
#game-content
{
margin-top:50px;
overflow:auto;
height:1000px;
width:100%;
}
#game-wrapper
{
float:left;
margin-left:90px;
position:relative;
height:100%;
}
or
body, html { /* both to be sized */
height: 1000px; /* or 100% */
}
A block element gets it height according to the content it has. Since you are giving a percentage height to the parent #game-content which does not have a well defined child content height (you are giving the child too in pixels), it is creating this problem. Giving a specific height to the parent solves the problem.
#game-content
{
margin-top:50px;
overflow:auto;
height:someheight px;
width:100%;
}
#game-wrapper
{
float:left;
margin-left:90px;
position:relative;
height:100%;
}
what i am looking at is a common issue with floating elements. a element that is floated does not affect its parents as one would expect. simply floating the parent element, in this case #game-content will do the trick.
#game-content
{
float:left; /* just need this one line */
margin-top:50px;
overflow:auto;
height:100%;
width:100%;
}
Hi below is my css & html,i'm trying to align two div in a webpage with full height(100%) but is not working
.left_menu
{
height:100% !important;
width:30%;
border:1px solid grey;
float:left;
}
.right_menu
{
height:100% !important;
width:70%;
border:1px solid grey;
float:right;
}
and this is my html
<div class="left_menu">
</div>
<div class="right_menu">
</div>
this code is not taking full height,please help
set html,body min-height to 100%
Child occupies the height of parent so 100% height of parent will give 100% height to child
Considering that you div is direct child of html,body(if not then you need to maintain the height ratio with its parent)
html,body{
height:100%;
min-height:100%;
}
Just add display: inline-block; and it should solve the problem (did for me)
You set the height of the div to 100% but 100% of what? It's always 100% of the parent element but what is the parent element of the div set to? My bet is you don't have it set to anything and the browser has no way of calculating what 100% of nothing is.
I think that problem is in your border properties as they are adding extra space. So, I am not sure if this fit best your needs, but I would do something like this:
.left_menu
{
height:100% !important;
width:29%;
border:1px solid grey;
float:left;
}
.right_menu
{
height:100% !important;
width:69%;
border:1px solid grey;
float:left;
}
EDIT:
This might be better solution, because previous one will work different for devices with different width(for small device right_menu goes under left_menu). Here I just specify width for left_menu.
.left_menu
{
height:100% !important;
width:30%;
border:1px solid grey;
float:left;
}
.right_menu
{
height:100% !important;
border:1px solid grey;
}
I am designing a webpage that needs to be split into 4 equal DIVs. This would be easy if I didn't also need to overlap text onto two of these DIVs. So, I have decided the best route would be to stack two container DIVs on top of each other, each with a width of 100% and height of 50%. Then, I would split these into two DIV classes, each with a height of 100% width of 50%, thus giving me 2 DIVs per container DIV, which are 2 in number.
My current CSS:
#collectionsTop {
width: 100%;
height: 50%;
overflow:hidden;
margin: 0 auto;
}
.topRight {
background-color:red;
width:50%;
height:100%;
float:left;
clear:both;
display:inline-block;
overflow:hidden;
}
.topLeft {
background-color:blue;
width:50%;
height:100%;
float:left;
clear:both;
display:inline-block;
overflow:hidden;
}
#collectionsBottom {
width: 100%;
height: 50%;
overflow:hidden;
margin: 0 auto;
}
.bottomRight {
background-color:yellow;
width:50%;
height:100%;
float:left;
clear:both;
display:inline-block;
overflow:hidden;
}
.bottomLeft {
background-color:green;
width:50%;
height:100%;
float:left;
clear:both;
display:inline-block;
overflow:hidden;
}
And my HTML:
<div id="collectionsTop">
<div class="topRight"><img src="http://www.solomovies.ch/uploads/blog/lorem-ipsum-1440x900-text-on.jpg"></div>
<div class="topLeft"><img src="http://www.solomovies.ch/uploads/blog/lorem-ipsum-1440x900-text-on.jpg"></div>
</div>
<div id="collectionsBottom">
<div class="bottomRight"><img src="http://www.solomovies.ch/uploads/blog/lorem-ipsum-1440x900-text-on.jpg"></div>
<div class="bottomLeft"><img src="http://www.solomovies.ch/uploads/blog/lorem-ipsum-1440x900-text-on.jpg"></div>
</div>
Apparently, none of the above works in any capacity at all, displaying the images in their full resolution, not floated, and in no way limited by their parent DIVs. I have no idea why. Please help.
You have placed - clear:both in the css of topLeft , topRight elements
idea => clear:both; - No floating elements allowed on the left or the right side of a specified element ,
hence in your case also similar thing is happening,
check this fiddle : http://jsfiddle.net/4q4Jz/
update:
now check the fiddle.. demo
remove all the `clear:both;
and try it.
`
Her is my css:
html {
/* force document to be 200% of window size */
min-height: 200%;
}
body {
height:auto;
margin:0 auto;
}
div#wrapper {
/* so that child divs with floats stay contained */
overflow:hidden;
margin:auto;
min-width:200%;
min-height:200%; /* doesn't work */
background-color:#000;
border:1px solid red;
}
div#content1 {
float:left;
min-width:45%;
min-height:45%; /* doesn't work */
background-color:#555;
border:1px solid green;
}
div#content2 {
float:right;
min-width:45%;
min-height:45%; /* doesn't work */
background-color:#777;
border:1px solid blue;
}
And html:
<div id="wrapper">
<div id="content1"></div>
<div id="content2"></div>
</div>
I would like for #content1 and #conent2 to always occupy 45% of the window regardless of content. In Firefox, at least, the min-width works but the min-height does not. Is it possible to set a min-height in this situation using percents?
You can reference the height property as a percentage only when the parent container is set at a fixed height. In this case, html is set to height:auto despite your explicit height:200%. Thus, having the wrapper divider set to a percentage height will not work and the subsequent percentage min-height child elements will be ineffective as well.
I have an outer div
position: relative;
overflow: hidden;
min-heigth: 450px;
containing a div
position: absolute;
top: 10px;
right: 10px;
The inner div is bigger than the min-heigth of the outer div and I see that the outer div is not scaling to the content of the inner div. Capping off the bottom content of the inner div.
How can I define the outer (or inner) div to scale vertically to the content (of the inner div)
Thanks
#trascher; It's possible but you have add extra markup because when you give a child div an absolute position then it's parent div is not consider it's height.
Check this http://jsfiddle.net/sandeep/6UksD/1/
CSS:
#outer
{
position: relative;
min-height: 450px;
background:red;
margin:10px 0 0 10px;
width:200px;
overflow: hidden;
}
#inner
{
position:relative;
background:black;
height:600px;
width:100px;
margin:10px 0 0 10px;
float:left;
}
#abinner
{
position:absolute;
background:yellow;
height:100%;
width:100%;
}
HTML:
<div id="outer">
<div id="inner">
<div id="abinner"></div>
</div>
</div>
First remove the min-heighton your outer div, and then instead of absolutely positioning the inner one, put a 10px padding on the outer one.
#outerDiv {
position:relative;
overflow:hidden;
padding:10px;
}
#innerDiv {
/*Stuff*/
}
Do provide us with an example though, it's hard to see the context...
Here's the stuff
<div id="outer">
<div id="inner"></div>
</div>
#outer
{
width:300px;
height:auto;
}
#inner
{
width:200px;
height:300px;
}
I think this is thing you want:http://jsfiddle.net/anish/ZjQTt/
set inner content height according to your wish.the outer div expanded automatically.
Absolute positioning doesn't increase the height of it's parent element.
You either set the height of the outer div manually
You make the inner div to have margin top/left of 10px
You increase the height of the outer div using javascript.