This question already has answers here:
How do you get the footer to stay at the bottom of a Web page?
(32 answers)
Closed 4 years ago.
I am trying to create a Single page application.
html content:
<div class="containerDiv">
<div class="headerDiv"></div>
<div class="contentDiv"></div>
<div class="footerDiv"></div>
</div>
All my application content will go inside contentDiv along with ng-view.
css content:
.containerDiv {
position: relative;
min-height: 100%;
background-color: beige;
}
.headerDiv {
height: 60px;
background: black;
width: 100%;
}
.contentDiv {
padding-bottom: 60px;
}
.footerDiv {
position: absolute;
left: 0;
bottom: 0;
right: 0;
background-color: pink;
width: 100%;
height: 60px;
}
Everything works fine with non-positioned elements and footer stay at the bottom, when content height increases.
I want to add positioned elements(absolute or relative) in the contentDiv as per my requirements.
When height of my positioned element increases, it breaks my page as footer remains at same position and elements overrides it.
Suppose I want to add a table in contentDiv
<div class="data">
<table>
</table>
</div>
I want to align table at particular location in html.
.data{
position:absolute/relative;
top: 300px;
left: 400px;
}
If height of the table increases, it will go out of the scope of footer.
The height of the table is dynamic.
Not sure what you're trying to achieve here.
If you want to have your footer always sticked to the bottom of the page, like "floating" over your page content, you need to set the footerDiv's position to fixed in your CSS.
JsFiddle example for fixed position
If instead you want the footer to not overflow anything, you can set the position to relative, since it's already at the bottom of your container layout.
JsFiddle example for relative position
Applying the answer from the duplicated question to your case, here is yet another solution for a sticky footer, w/o making it fixed
JsFiddle example for sticky footer w/o fixed
Related
This question already has answers here:
Fixed position Div ALWAYS appear on top?
(5 answers)
Closed 2 years ago.
I want a header throughout the page when I scroll so I use a header position as fixed.
.header-title{
letter-spacing: 0.2em;
display: flex;
align-items: center;
height: 10vh;
width: 100%;
position: fixed;
background: white;
}
I have used an image on my page with some text on it:
So I used position absolute.
.bottom-left{
position: absolute;
top: 5px;
left: 5px;
background: black;
color: white;
padding: 5px;
font-size: 19px;
}
When I scroll up the fixed position is overridden by absolute:
Actual page:
Doubt image:
The above picture shows the fixed position is overridden by absolute
When you set position:fixed on your header, this means it has come out of the normal flow of execution.
With this some of your page's content is available but behind the header itself. so a margin-top equal to the header height on the element after header will fix it.
You can also use a z-index:10 ( a value more that the position:absolute div) to make it come on top of the page.
Coming to your second part of the question that fixed is changed to absolute. I don't see that happening here.
This question already has answers here:
Why position:sticky is not working when the element is wrapped inside another one?
(1 answer)
Why bottom:0 doesn't work with position:sticky?
(2 answers)
Closed 3 years ago.
I have added this code to my website but there is no effect:
.wp-block-column:not(:first-child) {
position: sticky;
top: 0px;
}
Here I share a fiddle to demonstrate: https://jsfiddle.net/9xb0q8fw/1/
Screen must be at least 790px wide.
I would like that the right column stays sticky until the left column has passed while scrolling down.
But position:sticky; is not taking effekt.
Thank you for any help!
The sticky element in your fiddle has no height setting - use a set height to avoid that, then the sticky position works:
https://jsfiddle.net/rocz5nL1/
position: sticky only works when the parent element around it has a larger height, and when it reaches the end of that element it "bottoms out". So if the wrapping parent element is the same height as the sticky element, it never gets a chance to become sticky. See this demo for a working example of what I mean.
.container {
height: 900px;
}
.content-half {
float: left;
width: 50%;
background: #EEE;
}
.i-am-sticky {
position: sticky;
top: 0px;
padding: 10px;
margin: 10px;
border: 1px solid blue;
background-color: #333;
color: #FFF;
}
<div class="container">
<div class="content-half">
<div class="i-am-sticky">Sticky - not working b/c parent is too short</div>
</div>
<div class="content-half" style="height: 500px;">
<div class="i-am-sticky">Sticky - works b/c parent has height!</div>
</div>
</div>
I have a page like http://codepen.io/meek/pen/NNprYb
My problem is that the footer is not staying at the bottom of the page, only at the bottom of the first section.
HTML for footer:
<footer class="row-footer">
<div class="container">
<div class="row">
text
</div>
</div>
</footer>
and CSS:
footer {
width: 100%;
bottom: 0;
position: absolute;
height: 50px;
background-color: #ccc;
}
No matter what I try I can't get it to stay at the bottom. I'd like for it to be at the very end of the contact section.
clarification: I don't want it to be fixed, I just want it to be at the very bottom of the page.
Remove the height:100% from #content
Remove position:absolute from footer
Setting the height to 100% will only make it as tall as the windows/screen height. Removing it will make it "auto-expand".
Codepen Link
footer {
width: 100%;
bottom: 0;
position: fixed;
left: 0;
height: 50px;
background-color: #ccc;
}
OR
just do the following
Wrap the entire html inside a div lets call it wrapper
then
footer{
position: fixed;
top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px');
height: 50px;
background-color: #ccc;
}
This piece of code just calculates the top value of your footer div
Ok, using position: absolute; on footers is generally never a good idea since the footer no longer will move relative to the rest of the content on the site. I understand that you do not want to use position: fixed; since this will not give you the results you are looking for.
Your #content div currently has a constant height of 100% which will push the footer to somewhere in the middle of the content.
My solution would be to use a min-height: 100%; on the #content div and remove the position: absolute; (and bottom: 0;) from the footer.
Result: The content-divs' height will adapt to be more than 100% if more content is added. It will always be at least 100% and therefore the footer will always be pushed to the bottom of the page, even if the content only fills half the window size.
I've been looking into mimicking some websites to learn some new neat techniques.
And while doing so, I came up with some trouble emulating a certain site.
http://dangblast.com/ heres the link to the site.
If you look at the top of the website there is a div that contains a background image that has an "absolute" position and a "background-size" that covers and my question starts here.
Right underneath that div, there is another div (id = "about") that follows up right after and surprisingly the div always comes right after even if the window size is changed.
From my understating, I thought that it was impossible to stack an "abosolute" or "fixed" positioned div right after another, they just become layered.
Is there a trick to achieving this type of effect?
right now I have a div in my website that looks like the following
The Html
<div id = "fill_screen">
</div>
<div id = "followup_div">
</div>
The CSS
#fill_screen {
position: fixed;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
#followup_div {
background-color: yellow;
height: 500px;
width: 100%;
}
Is there a way to make divs fit right under a absolute or fixed positioned div that is also filling up the window of the screen? That is dynamic to the web-browser size?
I did some research and there were techniques using viewports height (vh), but I saw that some old browsers were not compatible with it.
You have to modify the position of the followup_div. The followup_div uses absolute positioning and has to be moved 100% from the top.
HTML:
<div id = "fill_screen">
<button>text</button>
</div>
<div id = "followup_div">
</div>
CSS:
body {
margin:0px;
}
#fill_screen {
position: fixed;
width: 100%;
height: 100%;
left: 0;
top: 0;
right:0;
bottom:0;
background-color:red;
}
#followup_div {
background-color: yellow;
height: 500px;
width: 100%;
position:absolute;
top:100%;
}
DEMO
If you take a look at the top of id="intro" you can see class="intro-down". this anchor makes space for fixed div and if you remove it you can see that id "intro"(which is a fixed div) will be disappeared.
I'm designing a website which has fixed elements on the outer edges of a fixed-width layout. A div in the center is reserved for the content.
When the user scrolls, I want all of the content (besides said fixed outer navigation elements) to stay within the borders of that center element.
Here's a quick mockup of what I mean:
I could very easily set the overflow property of the center element to auto, and have everything remain inside. However, it's very important that a scroll bar not be present on the edge of that element.
Basically, I'm wondering how to either:
Restrict content to that area
(perhaps I could change the size and
positioning of the body element -- is
that allowed? -- and then position
the fixed elements outside of the
body.
Hide the scroll bar that appears
inside the div when using
overflow:auto
Any help would be greatly appreciated!
If possible, you should break your fixed position elements up into 4 separate sections (top, left, right and bottom). Then just make sure you pad you centre content area by their respective widths and heights so the content doesn't get overlapped:
HTML
<!-- 4 fixed position elements that will overlap your content -->
<div id="top"></div>
<div id="left"></div>
<div id="right"></div>
<div id="bottom"></div>
<div id="content">
<!-- Your content -->
</div>
CSS
html, body {
height: 100%;
}
#top, #left, #right, #bottom {
position: fixed;
left: 0;
top: 0;
z-index: 2;
background: red;
}
#top, #bottom {
width: 100%;
height: 20px;
}
#bottom {
top: auto;
bottom: 0;
}
#left, #right {
height: 100%;
width: 20px;
}
#right {
left: auto;
right: 0;
}
#content {
position: relative;
z-index: 1;
padding: 25px; /* prevent content from being overlapped */
}
You can see it in action here.
Also note the position: relative on the content area. This is so z-index works correctly and the content is displayed below the fixed sections.
If you care about IE6/7 support, you'll need to add a CSS expression fix to get fixed position working properly in those awesome browsers.