IE - using 100% height within table-row - html

I'm using css tables where the last table row has height 100% - to fill up the remaining height.
FIDDLE
This works for me cross-browser (Including IE).
However, if I then add in the last table-row some divs with fixed height (this is dynamic content - I don't know how many of them there are) where the last div has height:100% - in order to fill up the last table-row. - like this:
FIDDLE -
this now doesn't work in IE (Even IE10)
What must I do to make this work in IE ?
(Edit: As correctly pointer out in the comments: It doesn't work in any browser - although in Chrome and firefox it looks like it works - the height:100% on the last div of the third row wasn't filling up the remaining height but rather taking up the complete height of row3...
So I attempted using table rows for row 3:- FIDDLE... Now this works in other browsers, but still doesn't work in IE!)
Markup
<div class="table">
<div class="row row1">row1</div>
<div class="row row2">row2</div>
<div class="row row3">
<div class="row3a">row3a</div>
<div class="row3b">row3b</div>
<div class="row3c">row3c</div> <!-- in IE this doesn't fill the last row -->
</div>
</div>
CSS
.table
{
display: table;
width: 600px;
height: 300px;
}
.row
{
display: table-row;
}
.row1
{
height: 50px;
background: pink;
}
.row2
{
height: 100px;
background: orange;
}
.row3
{
height: 100%;
background: yellow;
}
.row3a
{
height: 30px;
background: purple;
}
.row3b
{
height: 60px;
background: aqua;
}
.row3c
{
height: 100%;
background: brown;
}

Pure CSS, Cross-Browser Solution, Without using CSS Table Layout.
I actually recomend you to USE the CSS table layout if you can. (I don't know why you don't want it in your rows, its perfectly fine.)
OR the flexbox layout, although it's not properly implemented yet in all browsers..
--I just read in the comments that it didn't worked for you in IE, well: my solution does.. even with IE8.
Working Fiddle
HTML: I'm using the extra wrapper I mentioned in the comment.
<div class="table">
<div class="row1">row1</div>
<div class="row2">row2</div>
<div class="row3">
<div class="Wrapper">
<div class="row3a">row3a</div>
<div class="row3b">row3b</div>
<div class="row3c">row3c</div>
</div>
</div>
</div>
CSS: (most of it if for the backgrounds)
.table
{
width: 600px;
height: 900px;
}
.row1
{
height: 50px;
background: pink;
}
.row2
{
height: 100px;
background: orange;
}
.row3
{
background: yellow;
position: relative;
}
.row3a
{
height: 30px;
background: purple;
}
.row3b
{
height: 60px;
background: aqua;
}
.row3c
{
background: brown;
}
.Wrapper
{
position: absolute;
width: 100%;
height: 100%;
}
.table:before, .Wrapper:before
{
content: '';
height: 100%;
float: left;
}
.row3:after, .row3c:after
{
content: '';
display: block;
clear: left;
}

IE gives you the perfect result you wanted. You are rendering it as table-row. You don't need to set specific height to the last row for it to fill the remaining space.
You are actually doing it wrong by setting height to 100%;
Here 100% means the actual height of row3 and chrome renders it as you have written.
i.e row3c overflows its parent row3.
since you specified pixel heights for the remaining rows it won't fill. You need to specify
percentage heights for all ( row3a -> height: 20%, row3b -> height: 30%, row3c -> height: 50%)
it will work

You are giving height to table as 300px, Here is fiddle http://jsfiddle.net/yKPq3/11/ and assuming you want table to be filled 300px, you need to change .row3 to height:150px and .row3c to height:60px

Related

How percentage works in css

I'm a newbie in HTML and CSS. Today I want to make a checkout form like that:
I want height of checkout-option-header equal 50% checkout-option's, but It always bigger than I want. Like that:
As I understand the percentage will determine size of children by size of parents.
But why I can't use it right?
CSS file:
.checkout-container {
margin-left: 10%;
margin-right: 10%;
background: black;
overflow: hidden;
}
.checkout-container .checkout-option {
margin: 5%;
background: red;
min-height: 100px;
}
.review-container {
margin: 5%;
background: yellow;
min-height: 100px;
}
.information-container {
margin: 5%;
background: blue;
min-height: 100px;
}
.checkout-container .checkout-option .checkout-option-header {
background: yellow;
min-height: 50%;
}
.checkout-option-container {
background: green;
min-height: 50px;
}
HTML file:
<div class="checkout-container">
<div class="checkout-option">
<div class="checkout-option-header"></div>
<div class="checkout-option-container"></div>
</div>
<div class="review-container"></div>
<div class="information-container"></div>
</div>
I'm not sure if I actually understand what you are asking but your code seems to be working.
http://codepen.io/TheStonedTurtle/pen/NbNNxw
I copied your code added the below CSS.
.checkout-option {
border: 5px solid white;
}
If you're whole question is trying to understand how percentages work they are dependent on the parent element. I.E. if you have an element with 500px height and you give a child 50% height it will have 250px as that is 50% of 500. See these for more info:
https://developer.mozilla.org/en-US/docs/Web/CSS/percentage
You could also use flexbox to accomplish this with less CSS but it is a relatively new feature so it is not fully supported in I.E. yet.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Flexbox browser support: http://caniuse.com/#feat=flexbox
I copied and pasted your code but I didn't see such problem. The two boxes inside the .checkout-option are exactly 50% in height. Instead of min-height, use height because your .checkout-option is blocking the checkout-option-header.

Make a div with two widths

I have two divs next to each other. The div on the right is 300px x 335px. The div on the left goes all the way down the page. I want the width of the left div to go all the way until the right div. Then under the right div, it takes up the whole width of the page. Is this possible?
div elements are block level elements. So they are like square blocks. No, they can't work as you ask. However, you might Google for CSS Shapes to see if it can do what you wish but it's not available in all browsers and still isn't exactly the same as you request.
Here is some option either you can add min-width to the short div and long div to extend it. or you can add a background-color body to fake the illusion of it. but like Rob said there is no good way that can work out.
.short {
width: 100px; height: 100px;
background:red;
float:left;
//min-height: 500px;
}
.long {
width: 100px; height: 500px;
background:blue;
float:left;
//min-height: 500px;
}
.width {
width: 100%;
height: 200px;
background:yellow;
}
.clearfix {
overflow: auto;
zoom: 1;
}
body {
// background-color: red;
}
<div class="clearfix">
<div class="short"></div>
<div class="long"></div>
</div>
<div class="width"></div>
That is not possible, although you could always put another div under the one on the right and set the margin so that it looks like it's part of the one on the left.
This is one of the method to achieve what you want
CSS
#left1 {
margin-right: 300px;
height: 335px;
background: #aaa;
}
#right {
width: 300px;
height: 335px;
float: right;
}
#left2 {
background: #aaa;
border: 1px soild #000;
min-height: 300px;
}
<div id="right"></div>
<div id="left1"></div>
<div id="left2"></div>

Change order of floated divs with CSS

JSFIDDLE
I want to change the order of floated divs at a certain pixel size.
At default state they both have 50% width and they are next to each other.
Below 600px screen size (or w/e does not matter) I want the second div(red one) float above first div(yellow one).
How is this possible with CSS only solution?
HTML
<div class="yellow"></div>
<div class="red"></div>
CSS
.yellow {
background: yellow;
width: 50%;
height: 300px;
float:left;
}
.red {
background: red;
width: 50%;
height: 300px;
float:left;
}
#media screen and (max-width:600px) {
.yellow {
background: yellow;
width: 100%;
height: 300px;
float:left;
}
.red {
background: red;
width: 100%;
height: 300px;
float:left;
}
}
The solution I want is:
RED DIV
YELLOW DIV
but now it is:
YELLOW DIV
RED DIV
I know that you're asking how to accomplish this utilising floats, but as far as I know using pure CSS this is impossible (at least without using nasty positioning, which you've said you don't want to do).
As far as I know the only nice way to accomplish this with pure HTML/CSS is to utilise the new flexbox spec (a good starting point would probably be this css tricks article).
When you use flexbox you can use the order property on items to dictate which order items appear in (duh)
You can see an example of this in action here, the HTML code is similar to what you have, with an added wrapper element (I also fixed the DOCTYPE declaration):
<!DOCTYPE html>
<div class="wrapper">
<div class="yellow">
</div>
<div class="red">
</div>
</div>
The CSS is a little different:
.wrapper {
display: flex;
flex-flow: row wrap;
}
.yellow {
background: yellow;
width: 20%;
height: 300px;
}
.red {
background: red;
width: 20%;
height: 300px;
}
#media screen and (max-width:600px) {
.yellow {
order: 2;
width: 100%;
}
.red {
order: 1;
width: 100%;
}
}
I've also cleaned it up a little, you had duplicate code in your media query which didn't really need to be there.
The only downside to this is that it currently only works on around 80% of browsers as of writing:
http://caniuse.com/#search=flexbox
Depending on your target market that might be OK, you could use graceful degradation so that it appears correctly in all ways except the ordering on devices that don't support flexbox fully.
I guess you're also only really targeting mobile devices with reordering things, support there is good so it might work well for you.
Try to change your
HTML to this -
<div class="container">
<div class="yellow"></div>
<div class="red"></div>
</div>
and your #media query CSS to this -
#media screen and (max-width:600px) {
.container{
display:flex;
flex-direction: column-reverse;
}
.yellow {
background: yellow;
width: 100%;
height: 300px;
}
.red {
background: red;
width: 100%;
height: 300px;
} }
Here is a simple solution using negative margins and floats.
For the CSS, use the following:
#media screen and (max-width:600px) {
.yellow {
background: yellow;
width: 100%;
height: 300px;
float:left;
margin-top: 300px;
}
.red {
background: red;
width: 100%;
height: 300px;
float:left;
margin-left: -100%;
}
}
Your HTML remains the same as you posted.
Add a top margin to .yellow using margin-top: 300px (equal to the height of the
red div).
For the red div, add a negative left margin of 100%.
This will force the red div to position itself over the yellow div, but since you
have the yellow div a top margin, the yellow div pops out under the red div.
The trick is similar to that used for the Holy Grail 3-column layout design.
See demo: http://jsfiddle.net/audetwebdesign/jux84wzk/
So far, there are no mobile first answers, which is fewer lines of css, and other benefits. This does touch the html, so it's not the OP's question, for a CSS only approach it's the Flexbox answer from two other peeps, which I have voted up.
DEMO: http://jsfiddle.net/mhrf6d4n/
HTML, put in source order of the smallest viewport first:
<div class="red"></div>
<div class="yellow"></div>
CSS (put the shared, global to all viewports outside of media queries, combine shared selectors, then after put the min-width and put your floats in there)
.yellow, .red {
background: yellow;
height: 300px;
}
.red {
background: red;
}
#media screen and (min-width:600px) {
.yellow, .red {
float:left;
width:50%;
}
}

Create three divs such that the top and bottom ones have fixed height, and the middle one has dynamic height?

I want to create three, stacked divs. The top and the bottom ones will be of fixed height, whereas the one in the middle will have a dynamic height that expands to fill the remaining space:
I've tried numerous things, such as setting the height to auto. I do have a solution, but it involves JavaScript (i.e., calculating the remaining height) but I was wondering if there was a pure CSS solution.
There's a CSS solution, but it won't work in older browsers. You need to use the calc "function" that is new to CSS, combined with height: 100%. If you've never used height: 100% before, you know that every parent element of the one you want to be 100% tall must also be set to height:100%. calc can take a percentage value and subtract pixels from it, so you just need to set it to be 100% minus however tall the top and bottom divs are.
Supported by: IE9+, Firefox 4+, Chrome 19+, Safari 6+
http://caniuse.com/calc
HTML
<div id='top'></div>
<div id='mid'></div>
<div id='bot'></div>
CSS
html, body
{
height: 100%;
}
#top, #bot
{
height: 50px;
background: red;
}
#mid
{
height: calc(100% - 100px);
}
FIDDLE: http://jsfiddle.net/jakelauer/9cYUB/
One solution is to do it with position absolute.
The downside of this approach is that if the total height of surrounding is smaller then the sum of the fixed heights the container will not be visible anymore.
Another thing to be noted is that this is probably a bad solution if you want to target mobile devices. It always depends on the exact situation if this solution is suitable.
If i remember right you will only have problems with IE 6 (on desktop) which does not support the top bottom combination for the position absolute.
HTML
<div class="header"></div>
<div class="container"></div>
<div class="footer"></div>
CSS
.header, .container, .footer{
position: absolute;
outline: 1px solid black;
}
.header {
left: 0px;
top: 0px;
right : 0px;
height: 50px;
}
.container {
left: 0px;
top: 50px;
right : 0px;
bottom: 50px;
}
.footer {
left: 0px;
bottom: 0px;
right : 0px;
height: 50px;
}
JSFiddle
You can do it with a HTML table if you need older browser support, or if you need to support IE8+ or higher you could use the CSS table layout.
Here's a jsFiddle using CSS table layout.
HTML
<div>
<div>
<div>Fixed Height</div>
</div>
<div>
<div>
<div>Variable Height</div>
</div>
</div>
<div>
<div>Fixed Height</div>
</div>
</div>
CSS
html, body {
height:100%;
width: 100%;
margin: 0px;
padding: 0px;
text-align: center;
font-size: 20pt;
font-family: Verdana;
}
body > div {
display:table;
width: 100%;
height:100%;
}
body > div > div {
display: table-row;
}
body > div > div > div {
display: table-cell;
vertical-align: middle;
}
body > div > div:nth-child(odd) {
background: grey;
color: #FFF;
height: 100px;
}
body > div > div:nth-child(even) {
height:100%;
width:100%;
}
body > div > div:nth-child(even) >div {
height:100%;
width:100%;
overflow:hidden;
}
If i understand you request you need to use wrap div: http://www.cssstickyfooter.com/using-sticky-footer-code.html

Browsers not compatible, Parent Div's height is manipulated by Child Div's and the footer is pushed to the bottom. Pure CSS requested

What I am looking to achieve is all the three below
pushing the footer to the bottom of the page
also making the main div stay full sized all the time with the child divs
all the child div's remain same height
I tried so many ways to do it and I found a way. But what ever I have done is not compatible with Firefox, Safari and IE7 and below, Please help me, I am looking for something that works on all browsers and Pure CSS.
Thanks a lot friends.
html:
<body>
<div id="parent">
<div id="row">
<div id="childRight">content</div>
<div id="childLeft"></div>
</div>
</div>
<div id="footer">footer content</div>
CSS:
<style>
#parent{
height: auto !important;
min-height: 100%;
width: 400px;
background: grey;
overflow: auto;
display: table;
}
#footer{
height: 60px;
width: 400px;
background: yellow;
margin-top: -60px;
}
html, body{
height: 100%;
margin: 0;
}
#childRight, #childLeft{
display: table-cell;
width: 100px;
border: 1px solid black;
min-height: 100%;
}
#childRight{
background: green;
height: 100px;
}
#childLeft{
background: red;
height: 200px;
}
#row{
display: table-row;
background: blue;
}
</style>
JSfiddle example:
http://jsfiddle.net/yellowandred/UBUNJ/2/
I appreciate your help and suggestions friends. thanks in advance..
Change height of the left and right side div should be same...ex:200px.
and use fixed bottom property for footer.