Expanding a vertical div to the full height [closed] - html

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have an html page broken into 4 parts: Header, menu, content and footer.
Header is at the top, footer at the bottom. In between are the menu on the left and the content on the right.
The height of the page may be set by the menu or the content, depending on which is bigger (both can change).
I want to put a background on the menu block that extends to the footer, even if the actual menu items are much shorted. So, basically, I want the menu block to be filled in, based on the size of either it or the content, depending on which is bigger. Any ideas?

Demo: http://jsfiddle.net/176dgmhy/
This can not be achieved using anything but display table or javascript.
Display table-cell makes divs act like table cells but without cluttering the css with table elements like tr,td, and so on.
* {
border: 1px solid;
}
header {
padding: 20px;
text-align: center;
}
.cont {
width: 500px;
}
.wrap {
display: table;
width: 100%;
}
.wrap > * {
display: table-cell;
}
.menu {
width: 30%;
}
.wrap .stuff {
height: 200px;
}

You could set up the menu and content areas with display: table-cell:
//add the table div as well as the cell class to menu and content
<div class="header">header</div>
<div class="table">
<div class="cell menu">menu</div>
<div class="cell content">content</div>
</div>
</div>
<div class="footer">footer</div>
.header, .footer { width: 100%; height: 50px; }
.table { display: table; width: 100%; }
.cell { display: table-cell; }
.menu { width: 50px; }
.content { }
JSFiddle Demo

Method 1 :
Use flexbox
This is an example of how to achieve your goal using a flebox.
Method 2 :
One way to do so would be setting -
html, body {
height: 100%;
}
and then
div {
height: 100%;
}
This will allow the div to take full height of the screen.
But the drawback of this is that if the content is too big, then it might get cut on smaller screens
Here is a pen as an example

Related

Alignment of floated divs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've got two divs inside main container's div. First div got fixed width /160px/ and is floated to left, second div contains only button which should be aligned to the right so I set float to right.
Main div has 25% widht of the whole page width and I'm using bootstrap in my app.
Everything works fine until the widh of paret div small to fit both divs so the right one is moved under the left one - but is there some way how to align /center/ second div in this situaton? So where both divs are alone in the row, they should be aligned to center of parent, but when they are in the same row, first one should be aligned to left and second one to right or maybe to center of availible space /parent div widh minus 160px of the first div/.
Many thanks for any advice,
Peter
EDIT:
container style: width:25%;
first /left/ div style: float:left; widht:160px;
second /right/ div style: margin-top:5px;
Here's an example demonstrating how to do it.
#container
{
width: 25%;
background: red;
overflow: hidden;
}
#left
{
width: 160px;
height: 5em;
background: green;
float: left;
}
#right
{
float: right;
height: 5em;
background: blue;
}
#media (max-width: 872px)
{
#right
{
float: none;
clear: both;
text-align: center;
}
}
<div id='container'>
<div id='left'>
</div>
<div id='right'>
<button>
Button
</button>
</div>
</div>
You should use a #media query, with a breakpoint set to a viewport size where the two divs can't fit on the same line.
Then in that media query set the right div to
float: none;
clear: both;
text-align: center;
HINT: View the code-snippet results full-paged, and then resize your window to see the effects.

CSS - create two columns [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a problem with my school project. I want to make two columns on my page using css, but nothing is working...
Website : http://kitlab.pef.czu.cz/~wbdinfo141528/
CSS : http://kitlab.pef.czu.cz/~wbdinfo141528/css/style.css
I hope that there is some dumb mistake, but I can't figure out, where the problem is.
I want to place the right column next to the left one :
Your margin was taking up the entire row, that's why the second div was pushed down. You don't need margin, just set the width and display it as an inline-block. The inline-block means it'll still be a block, but will wrap like text - so if there's enough space for the second div to be in the same row as the first, it can be.
Replace CSS with this, comments for what was changed.
div.leva {
background: blueviolet;
/* float: left; */
/* margin: 5px 500px auto auto; */
width: 49%;
display: inline-block;
}
div.prava {
background: yellow;
/* float: left; */
/* margin: 5px auto auto 500px; */
display: inline-block;
width: 49%;
}
Alternatively, you can use a relative container div and set that to 100%, and have two absolute divs inside the container with 50% width.
HTML
<div class="container">
<div class="leftdiv"></div>
<div class="rightdiv"></div>
</div>
CSS
.container {
position: relative;
width: 100%;
}
.leftdiv, .rightdiv {
position: absolute;
width: 50%;
top: 0;
}
.leftdiv {
left: 0;
}
.rightdiv {
right: 0;
}
You must add margin:0 in div leva et prava http://jsfiddle.net/rvp5js2w/
At first glance your floats are incorrect.
The purple is floated right while the yellow is floated left.
Set a width (where width is less then total width of stranka/2) for each of these div's and then float them correctly and it should line up.

Expand div with floating children to their full height

UPDATE: The problem has been solved using the code provided by Pradeep, specifically the "clearfix" code. I asked this question in search of a way of keeping my wrapper <div> behind all of my content, i.e. extend its height to the full height of all its children, and considered using a moving <div> where in reality my problem was fully discussed in "What is a clearfix?" and in CSS clearfix demystified.
Essentialy my container <div> had floating elements within that were expanding past the bottom of my wrapper. I wanted the wrapper to be behind all of my content so that users could read the text that was on top. Applying this new CSS class clearfix to my wrapper <div> the problem was solved but a new one created. I lost the ability to center the <div> on the page, which I did not state in my original question below. The solution to being able to center it again without losing the "clearfix" solution was to use a parent <div> that has margin-left: auto and margin-right: auto set. See CSS clearfix how to over come the inability to center an element using it
The Origional Question:
http://jsfiddle.net/L7TKx/
I want my <div> to move with the page as the user scrolls down the page.
I have seen answers on this site as well as others stating that you need to add the postion:fixed property but when I do this, my div which was centered on the page is now left aligned and the scroll bar disappears, so you cannot view the rest of the content. I'm looking for a fix that keeps the scroll bar and as the user scrolls, the <div> follows.
See http://www.rustdome.hfbsite.com/ I want that off white background to follow behind the text as the user scrolls.
I have the following and have experimented with position:fixed but that disables the scroll bar.
#wrapper {
min-width: 740px;
max-width: 1000px;
width: 100%;
margin-left: auto;
margin-right: auto;
background-color: hsla(30,100%,97%,0.69);
height: 100%;
}
html {
min-height: 100%;
position: relative;
}
body {
height: 100%;
}
You can try below code:
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
Above css add in your css file..and Add "clearfix" class in your main div(wrapper).
Good luck...
Instead of using position:fixed you'll probably want to use background-attachment:fixed. This will just make the background fixed while the text keeps being scrollable.
Regarding Pradeep's code you could also have used a simpler approach. You just needed to add this rule to your CSS:
#wrapper::after {
content: "";
display: block;
clear: both;
height: 0;
}
You will probably want it to be a separate div entirely from the one that houses your content. I am assuming the #wrapper is the off-white thing you want to move around, and I'd try something like bellow.
HTML:
<html>
<body>
<div id="wrapper"></div>
<div id="content">
Your Content
</div>
</body></html>
CSS:
#wrapper {
min-width: 740px;
max-width: 1000px;
width: 100%;
position: fixed;
left: 50%;
margin-left: 500;
background-color: hsla(30,100%,97%,0.69);
height: 100%;
z-index: -1;
}
#background {
z-index:-2;
}

Unable to produce horizonzal scroll with css [duplicate]

This question already has answers here:
Horizontal scroll in DIV with many small DIV's inside (no text)
(2 answers)
Closed 9 years ago.
I have HTML structure like this :
<div class="wrapper">
<div class="fixed_column"></div>
<div class="fixed_column"></div>
<div class="fixed_column"></div>
</div>
Here is my CSS :
.wrapper{
width:500px;
float:left;
/*overflow-y:scroll;*/
overflow-x:scroll;
}
.fixed_column{
float: left;
height: 600px;
position: relative;
width: 250px;
}
So I want only two columns to fit inside my wrapper. And so without third column being present it fits inside.
Once I add the third column like in the HTML above, the third column doesn't stay in the same row but it drops to the next line and I end up with vertical scroller instead of horizontal. added overflow-x to my css and I don't get a horizontal scroll-bar but the third column still drops to the next line.
However I tried to increase wrapper to 750px and this time all three columns fit in the same line so I thought nothing is wrong with my css or did I think wrong?
Why would there not be horizontal scroll once my wrapper is 500px and I have three columns inside with width:250px on each.
Add white-space: nowrap; to the container, use inline-block instead of float, and use overflow-x instead of overflow-y.
This works:
http://jsfiddle.net/vXqY2/
.wrapper {
width: 600px;
white-space: nowrap;
overflow:scroll;
}
.fixed_column {
display: inline-block;
height: 100px;
width: 250px;
background-color: red;
}
The floated elements are going to automatically wrap down to the next level if they start going off the right of the parent container. That's how floats work. To keep them on the same line, you have a few options:
Make the parent container wider (as you did), but you'll need an extra element for the scrollbar
Switch from float: left; to display: inline-block; (as #Alex suggested), but you'll need to make concessions for IE7.
Switch from float: left; to display: table-cell;. Don't recommend this, I tried it and it turns out it's kind of painful :-p
See all techniques in a jsFiddle demo
It is because your fixed columns divs are only 250px so they never break the 505px container they are currently in.
Here try this.
example:
<div class="wrapper">
<div class="scroll-container">
<div class="fixed_column">A</div>
<div class="fixed_column">B</div>
<div class="fixed_column">C</div>
</div>
</div>
.wrapper {
width: 505px;
position:relative;
overflow-y: scroll;
overflow-x: scroll;
}
.scroll-container {
width:1000px;
}
.fixed_column {
float: left;
height: 600px;
position: relative;
width: 250px;
background-color: green;
}

CSS - fluid design, how to correctly position right floats below the opposing element?

So, I have this, when the screen is resized, the floater should move to the left. Simple enough - but I want it below the content element - any easy way to accomplish that?
Since DOM order can't change without javascript - is there a way to have it display the same (floater is floated to the right), but have the inner elements in different order?
The floater cannot have a set height, only width.
I tried doing it position absolute and change the DOM order, it mostly worked, but then the floater has to be lower (in px) than the content div, which is not the case for me, it gets over the content below.
Any ideas?
.floater
{
float: right;
width: 300px;
background-color: gray;
}
#media screen and (max-width: 650px) {
.floater
{
float: left;
}
}
<div>
<div class="floater"></div>
<div>
content content content content content content content content content content content content content content content content content content content content
</div>
</div>
Update
Given your comments, we are more or less back to basics now :)
We're setting the main content to take up the entire width but leave 300px on the right side with margin. Width defaults to auto and results in a liquidy feel when resized above the #media treshold; I'm going to float it left too to make it play nicely with the next column:
.content-main {float:left; margin-right:300px;}
Now, for the sidebar. We know that it's 300px wide, and we also know that there is that much space available right next to the main content. That area, however, is taken up by the main content's margin, effectively "pushing" the sidebar down. We'll just handle it with a negative margin:
.content-secondary {float: left; width: 300px; margin-left:-300px;}
Because of the way dimensions worked out for us so far, it doesn't actually matter (for this scenario at least) whether the sidebar is floated left or right. Personally I'd stick with "stacking" it in one direction which would be of benefit if you were to add yet another column.
Updated version here: http://jsfiddle.net/6VpTR/76/
Original Answer
Note that in your original code the right column would interfere with the main content because of the manner in which floating elements interact with non-floating ones. I'd strongly suggest looking into using an existing framework where the kinks have been worked out maybe cssgrid.net or 960.gs
That being said, see this fiddle here: http://jsfiddle.net/6VpTR/
As you can see I'm strongly in favour of semantic class names, and your original concern gets addressed by some html restructuring as well as creative use of floating and margins. Gutters should be added if you do not go with a pre-defined grid framework.
New Answer (works, but with one major caveat)
This new answer works great (IE9, Firefox tested [IE8 renders but does not recognized #media switch]), except it requires you know the height of the right column (the column can be whatever height, but it needs to be known). It does reverse the DOM order within the wrapper. I realize the height issue may be a problem for you, Madd0g (I'm not sure if by "cannot have a set height" also means you do not know the height of any particular usage), but this solution could work for others, so I decided to post it anyway.
HTML
<div class="wrapper">
<div class="content-main">Main Content</div>
<div class="content-secondary">Right column</div>
</div>
<div>Content below</div>
CSS
.wrapper {
padding-right: 300px;
}
.content-secondary {
float: right;
width: 300px;
background-color: gray;
margin-right: -300px;
margin-left: 0;
}
.content-main {
float:left;
background:orange;
min-width: 100%;
margin-right: -300px;
}
.content-main:before {
content: '';
width: 300px;
float: right;
margin-bottom: 1em; /*this needs to be set to height of right column */
}
.wrapper + div {
clear: both;
}
#media screen and (max-width: 650px) {
.content-main, .content-secondary
{
float:none;
margin: 0;
}
.content-main:before {
display: none;
}
.wrapper {
padding-right: 0;
}
}
Original Answer (works if no content below the wrapper)
Based on your comment to o.v., I think what you want is this:
HTML
<div class="wrapper">
<div class="content-secondary">Right column</div>
<div class="content-main">Main Content</div>
</div>
CSS
.wrapper {
position: relative;
}
.content-secondary
{
float: right;
width: 300px;
background-color: gray;
}
.content-main
{
background:orange;
}
#media screen and (max-width: 650px) {
.content-secondary {
float:none;
position: absolute;
top: 100%;
}
}
This works for me, atleast in Firefox...you just need another <div>
.floater
{
float: right;
width: 300px;
background-color: gray;
}
#media screen and (max-width: 650px) {
.floater
{
float: left;
}
}
<div>
<div>
content content content content content content content content content content content content content content content content content content content content
</div>
<div>
<div class="floater">a</div>
</div>
</div>