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>
Related
One example is better than a thousand words, so here you go:
https://jsfiddle.net/jesuxapo/os53cyc1/
As you can see, the height is responsive, but not completely. The problem is the <div id="k"> with fixed height of 150px. Try to play with it and I think you'll understand exactly what I mean. I want to get rid of this 'problem' somehow.
I could use the calc() of the css3, however it's not cross-browser(especially android and IE8-9).
Perhaps there's some other solution for this using html and css languages?
You may use the display:table properties (IE8 and later):https://jsfiddle.net/os53cyc1/1/
it will grow if content is more than 100vh all together
html, body {
padding: 0;
margin: 0;
height: 100%;
background: #333;
font-weight: bold;
color: #fff;
}
body {
display:table;
width:100%;
}
body>div {
display:table-row;
}
div {
border: solid 2px #FFFF00;
}
div#a {
position: relative;
background: #800000;
width: 100%;
height: 100%;
}
div#b {
position: absolute;
top: 0;
}
div#c {
position: absolute;
bottom: 0;
}
div#k {
height: 150px;
background: #008000;
}
<div id="k">
Hello, I'm K and I just broke your code
</div>
<div id="a"><br><br><br><br>
This is relative div with height of 100% and max-height of 500px
<div id="b">
This div is aligned to the top of the Red div
</div>
<div id="c">
This div aligned to bottom of the Red div
</div>
</div>
I have a page with the following basic layout:
<body>
<div id="header"></div>
<div id="wrapper ">
<div id="sidebar-container"><div id="sidebar"></div></div>
<div id="content"></div>
</div>
<div id="footer"></div>
</body>
The css is like this:
#wrapper {
clear: both;
float: left;
width: 100%;
height: auto;
}
#sidebar-container {
float:left;
width: 10%;
height: 100%;
min-height: 500px;
padding: 20px 0px 20px 0px;
background-color: green;
}
#sidebar {
width:100%;
height: 100%;
background-color: green;
}
#content {
float: left;
width: 90%;
height: 100%;
}
#footer {
clear: both;
position: absolute;
width: 100%;
bottom: 0;
margin: 0 auto;
height: 100px;
background: url("footer.jpg") repeat-x scroll 0 0 rgba(0, 0, 0, 0);
}
At present, the contents of #sidebar-container and #content determine the height of #wrapper. I'd like to get the divs within #wrapper to extent to the footer, which is positioned at the bottom of the browser window. Any suggestions on how to do this? Thank you.
If you support IE9 and up, you can use calc.
#wrapper {
position: relative;
height: calc(100% - {yourFooterHeight}px);
}
#wrapper > * {
height: 100%;
}
Example
body, html {
position: relative;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#wrapper {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: calc(100% - 100px);
}
#wrapper > * {
height: 100%;
}
#content { background-color: #ebd24b; }
#footer {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100px;
background-color: #000;
}
<div id="wrapper">
<div id="content"></div>
</div>
<div id="footer"></div>
From what I understand, you may need to use position: fixed for the sidebar and content. A height: 100% doesn't work on elements without a position of fixed or absolute.
You'll have to update some of your other styles, like removing floats, etc., but I believe what you're trying to do requires fixed or absolute positioning. Read more about the difference here: http://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/
Additionally, I would recommend investigating semantic HTML tags like footer and header. This doesn't affect the layout here, but it would be good to get in the habit.
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/HTML5_element_list
It can be a challenge as you content and sidebar have no relationship i.e. both on same level. You would need to have one of them be the parent of the other or you would need to write some JS. You can use pseudo elements in pure CSS, but in essence you would still need to have one of them "lead" as some element needs to be the box size relationship master.
Example, in Angular I use the following directive. You can then use min-height on the right column to keep a min height, after that it will automatically adjust the left (sidebar) to match the content area:
mmeMain.directive('mirror', function () {
return {
restrict: 'A',
link: function (scope, elem, attr) {
scope.$watch(function () {
angular.element(document.getElementById(attr.mirrorReflect)).height(elem.height()-85);
});
}
};
});
HTML
<div id="leftColumn" class=sidebar col-xs-6 ">
// html code
</div>
<div id="rightColumn" class="content form-column col-xs-6" mirror mirror-reflect="leftColumn" >
// html code
</div>
I'd like to have a sticky header with a %-height property. Sections below the header should take up the remaining height of the page, for example: header=10% all other sections are atleast 90%. This is similar to a related question: CSS Sticky Header/Footer and Fully Stretched Middle Area?, but he's using fixed px-height whereas i want %-height. I tried to use margin on my section, but that doesn't seem to work. Not does it seem to work to use a margin and 90% height on my sections.
For the moment I was able to come up with: http://jsfiddle.net/K9m63/. But a few problems:
The first section dissapears underneath the header.
Because of point 1, the section div's are too high and therefore not taking the remaining size.
HTML
<header>
<nav>Test</nav>
</header>
<section>
<div class="container yellow">1</div>
</section>
<section>
<div class="container pink">2</div>
</section>
<section>
<div class="container purple">3</div>
</section>
CSS
body, html {
height: 100%;
}
header {
height: 10%;
background-color: green;
position: fixed;
top: 0px;
width: 100%;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.nav-image {
vertical-align: middle;
}
section {
height: 100%;
width: 100%;
background-color: red;
}
.container {
width: 72.8125%;
background-color: blue;
margin: 0px auto;
height: 100%;
}
.yellow {
background-color: yellow;
}
.pink {
background-color: pink;
}
.purple {
background-color: purple;
}
Thanks!
Possible solution:
I have wrapped all sections into 2 divs.
<div class="wrapper">//rest 90% of the page
<div class="wrapper2">//100% of parent
<section>
<div class="container yellow">1</div>
</section>
<section>...
</div>
</div>
CSS:
.wrapper {
min-height:90%;
height:auto !important;
position:relative;
top:10%;
}
.wrapper2 {
height:100%;
width:100%;
position:absolute;
}
Also, add z-index:1; to header.
Updated fiddle here.
Based on your drawing, this is how you could* do it. - but there's also "fixed" / or "Sticky" positioning. - and this layout would force you to implement your own scroll below - in the page content, which is a pain.
html, body {
height: 100vh; /* you can use vh or % - but either way... */
height: 100%; /* they don't know their own height... how would they? */
}
body {
margin: 0;
}
.site-header {
background: #ff6666;
height: 10%;
}
.page-content {
background: #6666ff;
height: 90%;
}
<header class="site-header">
header
</header>
<main class="page-content">
main
</main>
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;
}
I am working on a Joomla 2.5 template right now # http://development.aycdesign.net/skin , and have been stuck on this for days and google has been no friend on this issue. What I am trying to accomplish is to have a variable size header, variable size footer, and always have the content container a minimum of 100% of the browser window size. I've tried just about everything under the sun, and get two problems.
The container my content is in will not expand to 100% height of its container.
On pages that have to scroll, a portion of the content are is clipping into the footer.
Any suggestions on this would be greatly appreciated so that i can get this resolved and move on!
<html>
<body>
<div id="wrapper">
<div id="top">
header
</div>
<div id="mnav">
main menu
</div>
<div id="pagewidth">
<div id="maincol">
content
</div>
</div>
<div id="footer">
footer
</div>
</div>
</body>
</html>
....and the css:
html,body {
height:100%;
background: rgb(138, 126, 102);
color: #A5A56F;
font-family: arial, sans-serif;
font-size: .9em;
line-height: 1.25;
}
/* ******************************************************************** */
/* Wireframe Elements */
/* ******************************************************************** */
#wrapper {
position: relative;
height:auto !important;
height:100%;
min-height:100%;
}
#top {
background: rgb(0, 0, 0);
width: 100%;
}
#top .custom {
width: 80%;
margin: 0 auto 0 auto;
color: #fff;
text-align: right;
padding: .5em 0 .5em;
}
#pagewidth {
width: 80%;
min-height: 100%;
background: rgba(54, 54, 54, 0.5);
text-align: left;
margin: 0 auto;
padding-bottom: 3em;
}
#maincol {
}
#footer {
background: rgb(0, 0, 0);
width: 100%;
height: 5%;
position: absolute;
bottom: 0;
}
#footer .custom {
width: 80%;
margin: 0 auto;
color: #fff;
text-align: right;
padding: .5em 0 .5em 0;
}
Try adding the following CSS to #pagewidth :
position: absolute;
top: 20px;
bottom: 5%; /* To keep the content from stretching past the footer */
left: 50%;
margin-left: -40%;
http://jsfiddle.net/H8sg8/
When you have an element whose position is set to either absolute or fixed, you can use both top and bottom to stretch it to be those distances from the top and bottom of its container, respectively. The same can be used for left and right.
Example here
The problem is that your child container does not know the height of it's parent in order to calculate it's own height. Thankfully a lot of work has gone into looking at this problem in the past.
I like to set up my pages like this in order to get a flexible page with a sticky footer.
I'll demonstrate two ways to do it. One for modern browsers and one for if you want to support legacy ones (ie7, ie8, firefox < 17)
HTML
Modern browsers
<div class="page">
<div class="page-header">
<div class="container">
</div>
</div>
<div class="container">
<!--Main content goes here-->
</div>
</div>
<div class="page-footer">
<div class="container">
</div>
</div>
Legacy browsers
<div class="page no-box">
<div class="page-header">
<div class="container">
</div>
</div>
<div class="container">
<!--Main content goes here-->
</div>
<div class="page-push">
<!--Acts as a buffer against the footer-->
</div>
</div>
<div class="page-footer">
<div class="container">
</div>
</div>
CSS
html, body {
height: 100%;
margin: 0;
position: relative;
}
.page {
min-height: 100%;
position: relative;
/* Same height as the footer*/
margin-bottom: -150px;
padding-bottom: 150px;
/* These allow the box model to include padding and margin*/
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.page.no-box {
padding-bottom: 0;
}
.page-push, .page-footer {
height: 150px;
}
.page-footer {
/*make sure it sits on top*/
position: relative;
z-index: 1;
}
.container {
margin: 0 auto;
width: 80%;
max-width: 1140px;
}
I use this system a lot in my work and have created a responsive grid based on it that you can have a look at here. Hopefully this all makes sense to you.
I ended up using JS to solve this....
function sizeContent()
{
var contentHeight = $("#outer-container").height();
var newHeight = $("html").height() - $("#top").height() - $("#footer").height();
if (contentHeight < newHeight)
{
$("#outer-container").css("height", newHeight + "px");
}
}
//Initial load of page
jQuery(window).load(sizeContent);
//Every resize of window
jQuery(window).resize(sizeContent);