Responsive 2-column layout trouble - html

I'm having trouble solving this puzzle: I'm using a 2-column layout with a fixed-width right column and a left column which takes out the remaining space. Both heights are variable. So something like this:
<div class="sidebar">sidebar</div>
<div class="main-area">main content</div>
<style>
.sidebar { float: right; width: 250px; }
.main-area { position: relative; overflow: hidden; }
</style>
Ok, so up to here everything is fine. But here comes the tricky bit. I'm using CSS3 to enable a css change when reaching a max-width of 750px. I want the sidebar to break down below and have a 100% width (so it becomes a footer for the main content). But, because in the HTML code the sidebar div is required to be first it always appears above the main area.
Any ideas on how to lay this out?
Thank you very much!

The simple answer to your question is no. You can't make your sidebar move beneath the content in your breakpoint if the sidebar falls before the content area in your HTML. At least... Not without javascript and a bunch of craziness.
That said... Just move your sidebar below your main-content div. Semantically there is no reason for you not to.
<section class="container">
<div class="main-area">main content</div>
<div class="sidebar">sidebar</div>
</section>
Some CSS changes are required to achieve this however. It's not quite as simply done as you had it previously, but not especially difficult either.
.container {
position: relative;
}
.sidebar {
position: absolute;
top: 0;
right: 0;
width: 250px;
}
.main-area {
background: red;
margin-right: 250px;
}
Here is a JSFiddle demonstrating it working.
Feel free to add varying amounts of content to either the main-content area or the sidebar and you'll see that both still have varying heights that don't interfere with each other.

HTML:
<section class="container">
<div class="main-area">main content</div>
<div class="sidebar">sidebar</div>
</section>
CSS:
.container {
position: relative;
max-width: 1024px; /* could be width: x% as well*/
}
.sidebar {
position: absolute;
right: 0; top: 0;
width: 250px;
}
.main-area {
margin-right: 260px; /* sidebar width plus 10px gap */
}
#media only screen and (max-width: 750px) {
.sidebar {
position: static;
width: 100%;
}
.main-area {
width: 100%;
margin-right: 0;
}
}

I think you can realize this with jQuery.
HTML
<div class="main-area"></div>
<div class="sidebar"></div>
CSS
.sidebar{
background-color: #000;
height: 200px;
width: 50%;
}
.main-area{
position: relative;
background-color: #ff0000;
height: 200px;
width: 50%;
}
jQuery
$(function(){
$('.sidebar').css('float', 'right');
$('.main-area').css('float', 'left');
$(window).resize(function(){
if($(this).width() <= 750){
$('.main-area').removeAttr('style');
$('.sidebar').removeAttr('style');
}else{
$('.sidebar').css('float', 'right');
$('.main-area').css('float', 'left');
}
});
});
You can see result here -> jsFiddle
Well, this is my way.

I think I found the answer here: http://jsfiddle.net/salman/TPNpy/
<div id="main-area-wrap">
<div id="main-area">Column 1</div>
</div>
<div id="sidebar">Column 2</div>
<div id="clear"></div>
#main-area-wrap{
float: left;
width: 100%;
}
#main-area {
background-color: cyan;
margin-right: 200px;
}
#sidebar{
background-color: lime;
float: left;
width: 200px;
margin-left: -200px;
}

Related

How to prevent fixed bottom bar from hiding content

I have a fixed div that is covering up content on the bottom of my page when the user scrolls down. This specifically impacts mobile devices. I've recreated the problem here: http://codepen.io/bkuhl/pen/LWjXdx
Here's the code from that post:
<div class="main-content">
Test Content
<div class="content-suffix">
Copyright
</div>
</div>
<div class="fixed-bottom-bar">
I'm covering up the Copyright text
</div>
and CSS:
.main-content {
width: 100%;
min-height: 400px;
background-color: darkgrey;
}
.content-suffix {
padding-top: 350px;
}
.fixed-bottom-bar {
position: fixed;
bottom: 0;
right: 0;
padding: 1em;
width: 100%;
background-color: blue;
}
One approach I've thought about is adding a [padding|margin]-bottom to the content-suffix, but in this case my content on the fixed element has a variable length.
How can I make sure the "Copyright" text isn't covered by the fixed element, keeping in mind the fixed-bottom-bar has a variable text length?
You could use the css calc() property to achieve this. Add margin-bottom: calc(/* the values you want to calculate */); You haven't set the font-size, but the default is 16px. Therefore, you would want to add padding to the bottom of content-suffix that would be 16px + 2em, the total height of the footer. Your final code would be:
.content-suffix {
padding-top: 350px;
margin-bottom: calc(16px + 2em);
}
This would work better if you specified the font-size of the text somewhere. This could be a dynamic value (e.g. 1vw, 1em, etc.) and this would still work.
You need to set position to absolute, give overflow-y will be more better and calc for your height.
.main-content {
width: 100%;
height : calc(100% - 94px) !important;
background-color: darkgrey;
overflow-y : auto;
position:absolute;
}
.content-suffix {
padding-top: 350px;
}
.fixed-bottom-bar {
position: fixed;
bottom: 0;
height : 50px;
right: 0;
padding: 1em;
width: 100%;
background-color: blue;
}
<div class="main-content">
Test Content
<div class="content-suffix">
Copyright
</div>
</div>
<div class="fixed-bottom-bar">
I'm covering up the Copyright text
</div>
If the footer is simple you can add it at the bottom of the content and make it hidden so it will take space but will not be displayed.
.main-content {
width: 100%;
background-color: darkgrey;
}
.content {
display: flex;
align-items: flex-end;
height: 400px;
}
.bottom-bar {
width: 100%;
background-color: blue;
}
.bottom-bar.space {
visibility: hidden; /* hides the element but keeps it space*/
}
.bottom-bar.fixed {
position: fixed;
bottom: 0;
}
<div class="main-content">
<div class='content'>Test Content</div>
<div class="bottom-bar space">
I'm covering up the<br> Copyright text
</div>
<div class="bottom-bar fixed">
I'm covering up the<br> Copyright text
</div>
</div>
If you have no restriction for using JavaScript, look at below codes:
var x =
document.getElementsByClassName("fixed-bottom-bar");
document.getElementById("forged-fixed-bottom-bar").style.height = "" + x[0].offsetHeight + "px";
.main-content {
width: 100%;
min-height: 400px;
background-color: darkgrey;
}
.content-suffix {
padding-top: 350px;
}
.fixed-bottom-bar {
position: fixed;
bottom: 0;
right: 0;
padding: 1em;
width: 100%;
background-color: blue;
}
#forged-fixed-bottom-bar {
height: 20px
}
<div class="main-content">
Test Content
<div class="content-suffix">
Copyright
</div>
</div>
<div id="forged-fixed-bottom-bar">
</div>
<div class="fixed-bottom-bar">
I'm covering up the Copyright text
</div>

How do I let a div fill in the blank space

I have this page with several images. On the left is a bigger image that covers 32% of the width of the page and on the right there is a 6 image grid that covers the other 68% of thw width.
I have the images resize as the page width increases or decreases and that works beautifully.
At the bottom I have a navigation menu. The problem I have is with the navigation menu.
When resizing the page the images correctly respond but that leaves a white space between the menu and the images. I want to fill that gap. I tried to lett the menu fill in that blank space but couldn't get that figured out. then I suddenly realised that that would look terrible on phone's and such as the images would become terribly small and the menu would end up on over half of the page.
So my question is: what is a good way to fix my problem? Do I need to take a whole different approach?
EDIT: I'm familiar with the concept of responsive and know there are frameworks, but the frameworks i know of only offer a Grid layout and this site has to cover the entire screen on every resolution (per client request) So if you know how to do that with something like Bootstrap let me know.
If this is not possible at all, also please let me know so I can tell the client.
Heres a quick Fiddle (Image resolutions are accurate resolutions)
HTML
<div class="content">
<div class="left">
<div id="big-block">
<img id="red-tiger" src="img/tijger2.png" alt="Tijger"/>
</div>
</div>
<div class="right">
<img class="block" id="red-cat" src="img/plaatje1.png" alt="Rode Kat"/>
<img class="block" id="wild-dog" src="img/plaatje2.png" alt="Wilde Hond"/>
<img class="block" id="red-panda" src="img/plaatje3.png" alt="Rode Panda"/>
<img class="block" id="white-tiger" src="img/plaatje4.png" alt="Siverische Tijger"/>
<img class="block" id="puppys" src="img/plaatje5.png" alt="Puppy's"/>
<img class="block" id="grey-cat" src="img/plaatje6.png" alt="Grijze Kat"/>
</div>
</div>
<div class="footer">
<ul class="menu">
<li>HOME</li>
<li>EIGEN ONTWERP</li>
<li>GALLERIJ</li>
<li>WEBSHOP</li>
<li>CONTACT</li>
</ul>
</div>
CSS
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 0;
width: 100%;
height: 100%;
}
img {
width: 100%;
}
.content {
width: 100%;
padding-bottom: 45%;
}
/* block width */
.left, .right {
float: left;
}
.left {
width: 32%;
}
.right {
width: 68%;
}
/* smaller blocks */
.block {
width: 33.33%;
float: left;
}
/* footer */
.footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
padding-bottom: 4.6%;
background-color: black;
}
/* menu */
.footer > ul {
list-style-type: none;
margin: 0;
}
.footer > ul > li {
width: 20%;
float: left;
line-height: 30px;
text-align: center;
}
.footer > ul > li > a {
font-family:'Fjalla One', sans-serif;
color: white;
text-decoration: none;
}
.footer > ul > li > a:hover {
color: orange;
}
As we've discussed, using a responsive framework is the way to go. I would suggest bootstrap.
problem is all the frameworks I know of offer Grid layout only and
this site should be screen wide on any screen.
Again, as I said in my comment, thats not actually right. Bootstrap has a class container-fluid that will make the container span the full width. see - http://getbootstrap.com/css/#grid-example-fluid.
With regards to the sticky footer, this is possible too, see - http://getbootstrap.com/examples/sticky-footer/
You have to use responsive layouts for it.. You have to use frameworks to achieve it easily... I suggest Bootstrap...
I have tried changing your fiddle. The images fill the gap but they do not look good. Here is the link http://jsfiddle.net/0an15t5y/2/
Changed a few css.
.content {
width: 100%;
height: 80%;
}
/* block width */
.left, .right {
float: left;
}
.left {
width: 32%;
}
.right {
width: 68%;
height: 100%;
}
/* smaller blocks */
.block {
width: 33.33%;
float: left;
height: 50%;
}
/* footer */
.footer {
position: absolute;
left: 0;
height: 20%;
width: 100%;
background-color: black;
}

Sidebar to fill height of entire page

This is perhaps a common question, but all the answers I have found around the web, didn't work properly.
I want to create a sidebar for my webpage, which fills the entire height of the webpage.
Then when you scroll the sidebars content should move along the rest of the sites content.
I tried this methods:
HTML:
<div id="wrapper">
<div id="sidebar"></div>
<div id="content-area"></div>
</div>
CSS:
body {
margin: 0;
}
#wrapper {
width: 100%;
}
#sidebar {
width: 280px;
position: absolute;
top: 0;
bottom: 0;
}
#content-area {
width: 900px;
margin-left: 280px;
}
..and:
HTML:
<div id="wrapper">
<div id="sidebar"></div>
<div id="content-area"></div>
</div>
CSS:
body {
height: auto;
min-height: 100%;
margin: 0;
}
#wrapper {
width: 100%;
height: 100%;
}
#sidebar {
width: 280px;
height: 100%;
float: left;
}
#content-area {
width: 900px;
height: 100%;
float: left;
}
The first one works fine, until the content is extended: http://jsfiddle.net/B3bCb/1/
If that happens then the sidebar stops according to the browser-window height.
The second one didn't worked at all: http://jsfiddle.net/B3bCb/2/
I have also tried the faux column method, but I need to have an CSS-shadow (which blur, spread and color, can be changed dynamically on the site) on my sidebar, which I cannot do properly in the faux column method (Faux column is just an image).
So how do I make my sidebar 100% in height, no matter how much content I have?
Making the sidebar position as "fixed" it stays, doesn't matter how much content you have. I don't know if I solve your problem but hope it helps ;)
Here's the code:
#sidebar {
width: 280px;
position: fixed;
top: 0;
bottom: 0;
background: blue; }
Here's the fiddle
The following css can be another alternative for this
#sidebar {
width: 280px;
position: fixed;
top: 0;
height:100%;
background: blue;
}
#content-area {
position:relative;
left: 280px; // width of your side box.
}
You have a couple of choices, but the gist is to do with CSS position.
The reason position: absolute; does not work is because it needs some tweaking for that to work. You need to disable scrolling on the html, body, and wrapper classes, and enable scrolling on the content-area.
html, body, wrapper {
overflow: hidden;
}
.content-area {
overflow: auto;
}
You can see an example of this here. It's a responsive sidebar layout I made.
The other option is to use a position: fixed; on the sidebar, as others have noted.
Check this fiddle http://jsfiddle.net/dJ654/2/
I have changed some styles
#sidebar {
width: 10%;
height: 100%;
position:fixed;
right:0px;
top:0px;
background-color:gray;
}
#content-area {
width: 90%;
height: 100%;
float: left;
background-color:green;
}

Half fixed, half scrollable layout that can be scrolled... CSS

I have an exotic design that needs the following. The left side must scroll, while the right side + top head must stay put (fixed). See attached image.
I can accomplish this by position: fixed on the top and right side. The top & right hand side stays put while the left scrolls.... BUT then the PROBLEM is that there is NO scroll bar anymore if anybody zooms in and you also cannot scroll left to right to see whole page
How would one attack such a layout?
Thank You.
Could not post code before - let me try again:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Exotic</title>
<style type="text/css">
#top {
background-color: #FF0;
width: 1800px;
height: 50px;
position: fixed;
left: 0px;
top: 0px;
}
#sideLeft {
float: left;
width: 950px;
background-color: #9C0;
clear: left;
}
#sidebarLeft {
background-color: #0CC;
height: 800px;
width: 300px;
float: left;
}
.list {
float: left;
width: 600px;
margin-top: 100px;
}
#ordoner {
background-color: #F90;
float: left;
width: 640px;
height: 800px;
position: fixed;
top: 50px;
left: 950px;
}
#sidebarRight {
width: 210px;
height: 800px;
position: fixed;
top: 50px;
left: 1590px;
background-color: #0CF;
}
</style>
</head>
<body>
<div id="top">
</div>
<div id="sideLeft">
<div id="sidebarLeft"><!--end #sidebarLeft--></div>
<div class="list"><!--end .lisist--></div>
<!--end #sideLeft--></div>
<div id="ordoner"><!--end #ordoner--></div>
<div id="sidebarRight"><!--end #sidebarRight--></div>
<div id="footer"></div>
</body>
</html>
Clarification:
My css reflects 2 things in the right hand side but the point is that the right and the top should be static while the left scrolls... AND they should be horizontally scrollable IF a user zooms :)
Also, I've tried wrapping things in a container div, but that has its own problems - it scrolls but never reaches the right hand side if the window is not maximized.
Thanks again.
To clarify: As an example to get my point across... please resize the stackoverflow window to half your horizontal screen size... Now see how you can scroll left to right? If you zoom in, you can scroll left to right also to see the whole page. Well, in my layout, which works in full screen browser mode... once I resize that scroll bar at the bottom does not appear at all leaving the user with no ability to scroll horizontally. See picture below
Fiddle
http://jsfiddle.net/moby7000/tWb3e/
Its not very hard to create a layout like this.
I created one for you, see that Working Fiddle
HTML:
<div class="Container">
<div class="Header">
<p>The Header div height is not fixed (But he can be if you want it to)</p>
<p>This Layout has been tested on: IE10, IE9, IE8, FireFox, Chrome, Safari, Opera. using Pure CSS 2.1 only</p>
</div>
<div class="Content">
<div class="Wrapper">
<div class="RightContent">
<p>You can fix the width of this content.</p>
<p>if you wont, his width will stretch just as it needs to.</p>
</div>
<div class="LeftContent">
<p>this will scroll</p>
</div>
</div>
</div>
</div>
CSS:
*
{
margin: 0;
padding: 0;
}
html, body, .Container
{
height: 100%;
}
.Container:before
{
content: '';
height: 100%;
float: left;
}
.Header
{
margin-bottom: 10px;
background-color: #6ea364;
}
.Content
{
position: relative;
z-index: 1;
}
.Content:after
{
content: '';
clear: both;
display: block;
}
.Wrapper
{
position: absolute;
width: 100%;
height: 100%;
}
.Wrapper > div
{
height: 100%;
}
.LeftContent
{
background-color: purple;
overflow: auto;
}
.RightContent
{
background-color: orange;
float: right;
margin-left: 10px;
}
Bonus:
with a little change in the CSS, you can create a beautiful scrolling.
See that Fiddle
Edit:
If you want to set a width value to the left side, that is actually bigger then the body size (and to have an horizontal scroll), do it that way.
<div class="LeftContent">
<div style="width:1200px;"> <-- better to aplly the width from the CSS
..<The content>..
</div>
</div>
you need to add overflow:auto; to the area you want to scroll.
Have you tried
overflow-y: scroll;
in body?

Nested divs with mixed height mode (% & px) Keep the '%' div fill out space not used by the 'px' div

I want the "blue" container to always be 70px high, while the previous "green" div always max out the height available when the div is resized with javascript.
I've played around with it for a while without finding a proper solution. Help will be appreciated.
As promised, here's my answer.
absolute inside relative positioning is the easiest way to do this.
Live Demo
HTML:
<div id="parent">
<div id="left">height: 100%</div>
<div id="right">Content</div>
<div id="rightFooter">height: 70px</div>
</div>
CSS:
#parent {
position: relative;
height: 200px
}
#left, #right, #rightFooter {
position: absolute
}
#left {
width: 200px;
top: 0;
bottom: 0;
left: 0
}
#right {
top: 0;
right: 0;
bottom: 70px;
left: 200px;
overflow-y: auto
}
#rightFooter {
height: 70px;
right: 0;
bottom: 0;
left: 200px
}
Would something like this work?
Live Demo
Added an animation of the height so you can see the content extending.
Markup
<div id="parent">
<div class="left">
Lefty
</div>
<div class="right">
<div id="rightContent">
right Content
</div>
<div id="rightFooter">
Right Footer
</div>
</div>
<div class="clear"></div>
</div>
CSS
#parent{
height:300px;
}
.left{
float: left;
width: 33%;
background: red;
height:100%;
}
.right{
float : left;
width: 66%;
height:100%;
}
#rightContent{
height: 100%;
background: blue;
}
#rightFooter{
background: yellow;
height: 70px;
float: right;
width: 100%;
margin-top: -70px;
}
.clear{
clear:both;
}
Bah, before the comments come this is a partial solution, the text for the content area will bleed into the footer... looking at a solution for this, or someone else might be able to modify my markup/css to account for that.
Made an example for you here :)
you need to have a left floated div for the left content and a wrapper for the two other right divs, also floated left.
Take a look :)