How to keep content inside Footer and Header in React Component? - html

I know this might be asked a lot but somehow I can't find the solution. My project in React and my top component is setup up like this:
<Provider store={store}>
<Router>
<Header />
<Switch>
<All the routes />
</Switch>
<Footer />
</Router>
</Provider>
As you can see I want to use Header and Footer in all my pages. With my current setup, it works when my content height is bigger than view-height. I mean footer stays always on the bottom. The problem becomes on my smaller pages where the page content is smaller than view-height but my footer is still slightly below the view-height.
My current css code (didn't include unnecessary code):
Header
padding: "0.2em 4em"
Content-Wrapper
minHeight: "100%",
Footer
padding: "3em"
One of the pages on the link (that shows how footer is below the vh. Header stays at the top as a default block element and is fine ): Result

you should make use of flexbox in this case. Your code is in react but I will try to use html and css so you can understand the rules you have to apply. Look at this example:
.app {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.header {
position: sticky;
top: 0;
padding: 15px 5px;
background-color: pink
}
.footer {
padding: 15px 5px;
background-color: pink;
margin-top: auto;
}
<div class="app">
<div class="header">
Your Header
</div>
<div class="app-content">
Your will have routes here that will render your components as required
</div>
<div class="footer">
Your Footer
</div>
<div>
Trick here is to use margin-top on footer and it will produce the result you are looking for.
Let me know if you have any further question or confusion on this.

Related

Make content container div stretch when content is small/empty

I am currently working on a website where sometimes (for instance when the loading square comes up - like image below) the main content div is too small to fill the entire page with the footer/header.
I would like the main content that is in between the header and footer to stretch when the content div is too small, so that it fills the entire screen, while keeping the footer and header in view.
I have tried many different ways to do this, but all to no avail so far. The image below illustrates my problem.
The HTML layout looks like this:
<body>
<div class="nav-container"></div>
<div class="main-container"></div>
<footer></footer>
</body>
If you are familiar with flexbox, this would do the trick:
<body>
<header></header>
<div class="main-container"> Main content </div>
<footer></footer>
</body>
html, body {
margin: 0;
height: 100%;
min-height: 100%;
}
body {
display: flex;
flex-direction: column;
}
header, footer {
flex: none;
}
.main-container {
flex: auto;
}

Make footer not overlap content

I have 2 complications here, first is that how do I ensure that the footer does not overlap with the content of my articles. Now it seems to overlap the things above it and I can't seem to make the scrollbar with overflow: auto;
Also, how do I make the <hr>tag work becuase now it seems to mess up my entire flexbox and it only hovers above the first contact footer detail.
Thanks a lot for all your help!!!
#footer {
position: absolute;
left: 20%;
bottom: 0%;
width: 50%;
height: 20%;
display: flex;
justify-content: space-between;
}
.contact_footer {
margin-left: 20%;
}
<footer>
<div id="footer">
<div class="container">
<div class="contact_footer">
<hr>
<h3>Contact</h3>
<address>
info
</address>
</div>
<div class="contact_footer">
<h3>Address</h3>
<address>
info
</address>
</div>
</div>
</div>
</footer>
If you position anything absolutely, it is removed from the normal layout. If you don't want it to overlap with anything below it, you need to make sure there is nothing below it. This is not a tweak for your footer, but for your content.
Try something like this (selectors must be replaced with yours):
#content {
margin-bottom: 20vh;
}
20vh are 20% of the height of the screen, which might to be the size of your footer (your code doesn't make it clear what element your footer is positioned in).
Do one thing, for second problem
use pseudo class ':first-child' for only first footer content css and use 'border-top' style property instead of 'hr' tag
.contact_footer:first-child address{border-bottom:1px solid black;}

HTML bootstrap footer is not responding as it should. It is not sticking at the bottom and also not showing 100% width as I have programmed

I am making a small Sinatra app and using bootstrap for layout. But it is giving some issues.
It is not sticking at the bottom and also not showing 100% width as I have programmed. Also, the text of the footer is not getting centralized after even trying the text-center class.
Below is my HTML for the footer.
<div class="container-fluid">
<footer id="footer">
<p class="mx-auto">© 2017 <strong>Coding Tips</strong></p>
</footer>
</div>
Please also see below my CSS for the footer.
#footer {
background-color: white;
color: #111111;
position: relative;
z-index: 1
bottom: 0;
left: 0;
width: 100%;
/*height: 20px;*/
align-content: center;
}
Any suggestion to solve this problem?
There's a much easier way to create a sticky Bootstrap footer that doesn't require you to write any styles yourself. The Bootstrap navigation bar component comes with the .navbar-fixed-bottom class, alowing you to fix a navbar to the bottom of the screen. For an example,
p {
text-align: center;
padding: 10px
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-bottom">
<div class="container-fluid">
<p>© 2017 <strong>Coding Tips</strong></p>
</div>
</nav>
With this, you can get a fixed-to-bottom navigation bar that acts as a footer using pure Bootstrap.
Edit - Creating a sticky footer that expands with the page.
The previous example demonstrates how to create a footer that is fixed to the bottom of the viewport, superimposed over the page content. If you're looking for a footer that will only be fixed to the bottom of the screen when content is sparse, we can use flexible boxes.
body {
margin: 0; /* To ensure the footer takes up the full width of the viewport */
}
.container {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.content {
flex: 1;
}
footer {
text-align: center;
}
<div class="container">
<div class="content">
Your content goes here.
</div>
<footer>
<p>© 2017 <strong>Coding Tips</strong></p>
</footer>
</div>
The .content class automatically takes up the available space, forcing the footer to the bottom of the screen. Since we set the minimum height of .container to 100vh, it'll take up at least the entire height of the screen. Once more space is needed, the footer get's pushed down further. Flexbox provides what's probably the easiest and cleanest method of achieving this effect.
Bootstrap navbars: Components - Bootstrap
Solved by Flexbox: Sticky Footer - Solved by Flexbox - Cleaner, hack-free CSS
to align text in center please use
text-align: center;
the width is 100% as needed and
to place footer at the bottom you can give
top: 400px;
please check the given link https://jsfiddle.net/komal10041992/xn8mmg44/3/

Angular 2 sticky footer impementation

I want my footer to be a sticky footer and tried following the css tricks negative margin trick, but did not work. I tried to impersonate my angular2 app in the below plunker code. I want the sticker not be fixed but sticky and go to the bottom when there are more content available in the main section. Note the footer is displayed above the data in the main section.
http://plnkr.co/edit/WSUC4xLMWH6fY77UyFqI?p=preview&open=app%2Fapp.component.ts
app.component:
<nav-bar></nav-bar>
<section class="main">
<div class="main-container">
Display my router-outlet here
<ul>
<li *ngFor="let hero of heroes">
{{ hero }}
</li>
</ul>
</div>
</section>
<footer-component></footer-component>
Any help to fix and move the footer down is appreciated.
You can still follow this example mentioned by
https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/
Simply add this code to styles.scss
html,
body {
height: 100%;
}
In your app.component.scss
:host {
display: flex;
min-height: 100%; // used percent instead of vh due to safari bug.
flex-direction: column;
}
.Site-content {
flex: 1;
}
In your app.component.html
<header>...</header>
<main class="Site-content">..</main>
<footer>...</footer>
There are several ways to achieve this. I'm assuming you've tried one of these: CSS-tricks - Sticky footer, five ways.
For that to work, you would need to:
Remove absolute positioning of both the footer and the content.
Remove default top and bottom margins from body.
If you are not going with the flexbox or grid option, then place all content except for the footer inside of one element (so you can make sure the total height of that element plus the footer is at least the height of the viewport).
Here is an implementation of your Angular2 app with a sticky footer.
The sticky footer is achieved by wrapping all of the main content in a single div and using calc() to set it's minimum height to 100vh minus the footer's height.
I think it's not a good idea to make position:absolute for your .main block. Absolute positioning for your footer will be enough.
Try something like this
html {
height: 100%;
}
body {
min-height: 100%;
position: relative;
}
.main {
min-height: 100%;
padding-bottom: 55px;
}
#footer {
position: absolute;
bottom: 0;
}
Also remove margins and padding-top from .main block styles
You just have to edit 2 files:
index.html:
<!-- Full height body -->
<body class="pt-3 h-100">
<!-- Full height app container, and also use flexbox columns -->
<app-root class="d-flex flex-column h-100"></app-root>
</body>
app.component.html:
<router-outlet></router-outlet>
<!-- Footer top margin must be set on auto -->
<app-footer class="mt-auto"></app-footer>

How to make HTML content occupy all the available height?

Please, consider the following jsFiddle - http://jsfiddle.net/mark69_fnd/hwCuB/ (you can find the code after the body of the question).
It represents a trivial example of the classic header, content, footer HTML layout. Notice that:
The content never overlaps with the footer. Resizing the window will finally create a vertical scrollbar rather than move the content over the footer.
There are no redundant scrollbars.
No absolute heights, except of the footer, which may be assumed to be no higher than 2em.
The content height is less than the available height between the header and the footer.
I would like to keep the first three properties, but change the last one, so that the content height is the full height between the header and the footer. And I would like to do so without resorting to javascript.
How can I do so, if at all?
EDIT
The given html and css are just an example. You are free to change them as long as the final result satisfies the conditions of my question.
EDIT2
Apparently, I am not very clear on what I want to achieve with the content. Here is what I have now:
Notice how the content does not extend the full height available to it between the header and the footer.
What I am after is this:
(edited in mspaint, I do not know to do it really)
EDIT3
Added an except clause to the 3rd condition:
except of the footer, which may be assumed to be no higher than 2em.
HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.7.3/build/cssreset/reset-min.css">
</head>
<body>
<div class="container">
<div class="header">
Header goes here.
</div>
<div class="content">
<div class="innerWrapper">
Content goes here.
</div>
</div>
<div class="footer">
<div class="status">
Footer goes here.
<div>
</div>
</div>
</body>
</html>​
CSS:
html, body {
height: 100%;
width: 100%;
}
.container {
position: relative; /* needed for footer positioning*/
margin: 0 auto;
height: auto;
min-height: 100%;
background-color: #ddd;
}
.content {
padding: 0em 0em 2em; /* bottom padding for footer */
background-color: #bbb;
}
.footer {
position: absolute;
width: 100%;
bottom: 0; /* stick to bottom */
}
.status, .header {
background-color: #999;
border: solid 1px #000000;
}
​
There might be couple ways to do this, but the only ways i can think of at the moment all involve setting/knowing the height of your header and footer.
Here is one using display:table http://jsfiddle.net/fLnkf/
There may be other solutions depending on if your requirements allow you to change your html or use CSS3.
hope this helps!