Footer covers main content - html

I have tried many solutions in stackoverflow for my problem but somehow none work. Currently my footer covers the main content. This only happens when I shrink the page to the point where I'm in mobile view. I have to say that the footer should always be at the bottom. So if my main content is too short, the footer should still be at the bottom of the page. Currently I am using bootstrap 4.3.1.
My Site.css looks like this:
#footer {
position: absolute;
bottom: 0px;
}
Of course there are other lines in the Site.css. But they are not important for this.
And my layout looks like this:
<div class="jumbotron-fluid body-content">
<div id="main">
#RenderBody()
</div>
<footer id="footer" class="page-footer font-small blue pt-4 footerInfo">
<div class="row footerRow">
<div class="col-lg-3 footerCol">
<div class="footer-item text-center">
<div class="footer_icon d-flex flex-column justify-content-center ml-auto mr-auto">
<div class="fa fa-phone phoneIcon"></div>
</div>
<div><h3>Telefon</h3></div>
<div>12345</div>
</div>
</div>
</div>
</footer>
</div>
I don't want the footer covering my main content. The footer should grow downwards in the mobile view. Currently it is growing upwards and covers my complete content.
Can anyone help?
Thank you.

To use pure CSS, min-height: 100vh; display: flex; flex-direction:column on wrapper and flex-grow: 1 on main content are the way to go.
Or, simplified by Bootstrap classes:
<div class="d-flex flex-column" style="min-height: 100vh">
<main class="flex-fill"></main>
<footer></footer>
</div>
Short example:
/* not part of the solution, visual helper */
footer {
background-color: #369;
color: white;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex flex-column" style="min-height: 100vh">
<main class="flex-fill">
<div class="container-fluid">
<div class="row">
<div class="col">
#RenderBody()
</div>
</div>
</div>
</main>
<footer id="footer" class="page-footer font-small blue footerInfo">
<div class="container-fluid">
<div class="row footerRow">
<div class="col-lg-3 footerCol py-2">
<div class="footer-item text-center">
<div class="footer_icon d-flex flex-column justify-content-center ml-auto mr-auto">
<div class="fa fa-phone phoneIcon"></div>
</div>
<div>
<h3>Telefon</h3>
</div>
<div>12345</div>
</div>
</div>
</div>
</div>
</footer>
</div>
Tall example:
/* not part of the solution, visual helper */
main {
min-height: 200vh;
border: 1px solid red;
}
footer {
background-color: #369;
color: white;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex flex-column" style="min-height: 100vh;">
<main class="flex-fill">
<div class="container-fluid">
<div class="row">
<div class="col">
#RenderBody()
</div>
</div>
</div>
</main>
<footer id="footer" class="page-footer font-small blue footerInfo">
<div class="container-fluid">
<div class="row footerRow">
<div class="col-lg-3 footerCol py-2">
<div class="footer-item text-center">
<div class="footer_icon d-flex flex-column justify-content-center ml-auto mr-auto">
<div class="fa fa-phone phoneIcon"></div>
</div>
<div>
<h3>Telefon</h3>
</div>
<div>12345</div>
</div>
</div>
</div>
</div>
</footer>
</div>
Also please pay attention to the layout system. It works like a clock, but it's kind of delicate:
.col-*-* as direct descendants of .rows. If you need another division, place a .row inside a .col (i.e: .row > .col > .row > .col, never .col > .col or .row > .row)
never nest .containers! (you can have a .container inside a .container-fluid, though)

Did you use any media query to set behaviour at specific screen size?
below is a sample code
#media only screen and (max-device-width: 480px) {}
in your css

I suggest that you set your footer’s property to fixed position and overflow hidden

Related

Bootstrap 5 - Make div with flex-grow-1 class scrollable

I'm trying to make the indicated div below scrollable, but it always seems to extend the document size beyond screen space instead of creating a scrollbar. One solution is to set a fixed pixel height for the div, but I want to avoid this to ensure scalability between devices. Any ideas?
<div class="row no-gutters w-100 flex-grow-1">
<div class="col-8">
<div id="playarea" class="container-fluid border-top border-end h-100 px-0">
<!-- Cards go here -->
</div>
</div>
<div class="col-4">
<div class="container-fluid border rounded-top w-100 h-100 d-flex flex-column">
<div class="container my-3 d-flex mb-0">
<h5 class="flex-grow-1">Side Content</h5>
</div>
<hr class="border mt-2 mb-3">
<div class="container mb-3 d-flex">
<!-- Non-scrollable search area -->
</div>
<div class="container flex-grow-1 overflow-auto">
<!-- Scrollable content goes here -->
</div>
<div class="card mt-2 bg-light mb-3" id="info-panel">
<div class="card-body">
<!-- Non-scrollable info box -->
</div>
</div>
</div>
</div>
</div>
Many thanks in advance
Your question is a bit confusing because your .row has .flex-grow-1 which one would only add if you want .row to grow in available height of its parent, not in width. This would mean .row should always have a height and my solution can be simplified. So let me know if that's the case, because my answer assumes .row has no height.
My solution that requires no fixed height uses a container inside col-4 with absolute positioning:
#overflow-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: inherit;
}
This container will take up all available space inside col-4 and will grow or shrink with it. Now the element with overflow: scroll will work as you want.
The only drawback here is that if col-8 (or row) has no content - and thus no height - the #overflow-container will also have no height and any content inside the .overflow-auto element will not be visible. So if col-8 can be empty, a min-height on col-4s parent is needed.
The line padding: inherit is there to give the column its padding back; Bootstrap uses the selector row > * to give columns their padding.
I removed all unnecessary classes for this snippet to work for simplicity, but I added the sm breakpoint on the columns so they stack on mobile screen sizes. If you don't want this, you can simply remove the -sm part on the columns and the #media in the CSS. It's only there to show how it can be done.
.col-sm-8 {
background: lightyellow;
}
.col-sm-4 {
background: lightgreen;
}
#media (min-width: 576px) {
#overflow-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: inherit;
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<div class="container-fluid">
<div class="row">
<div class="col-sm-8">
<p>This column should have enough content...</p>
<br><br><br><br><br>
<p>...So `Overflowing content` will have a height.</p>
</div>
<div class="col-sm-4 position-relative">
<div class="d-flex flex-column" id="overflow-container">
<div class="">
<h5>Aside Content</h5>
</div>
<div class="">
<p>Some content here.</p>
</div>
<div class="overflow-auto">
<p>Overflowing content.</p>
<br><br><br><br><br><br><br><br><br>
<p>Unless col-8 is long enough for me to fit.</p>
</div>
<div class="">
<p>Some content here.</p>
</div>
</div>
</div>
</div>
</div>

PHP/HTML issue placing div content next to each other

I have a small issue. I am trying to create a Treeview of a number of categories pulled out of the database. These categories should be placed next to each other (with a little space between them). Have been trying quite some css styling etc, but always get those categories underneath each other, no matter what I try it seems. Also cleared my cache several times without success. Does anyone have an idea on how to get this done ? It is dynamically, so it can be that there are 2, 3 or more categories to be displayed next to one other. Those categories should have a Treeview of corresponding subcategories and documents which is not yet coded.
My relevant code so far :
<div class="d-flex two-column-wrapper" id="twocols-wrapper">
<main class="instruments-wrapper">
<div class="card bg-light col-md-6 offset-md-3">
<div class="card-header row align-items-center">
<h3 class="text-center"><?=$this->instrument->name?></h3>
</div>
<div class="content-wrapper">
<div class="content">
<?php foreach ($this->categories as $category):?>
<div class="category">
<li class='active'><?=$category->name?></li>
</div>
<?php endforeach;?>
</div>
</div>
</div>
</main>
</div>
And in CSS :
content{
width: auto;
position: fixed;
overflow: visible;
}
.category{
width: 200px;
display: inline-block;
float: left;
}
Any help is much appreciated !
You need to use the display: inline-block; CSS property on the <li> element. Like so...
<div class="d-flex two-column-wrapper" id="twocols-wrapper">
<main class="instruments-wrapper">
<div class="card bg-light col-md-6 offset-md-3">
<div class="card-header row align-items-center">
<h3 class="text-center">Drum</h3>
</div>
<div class="content-wrapper">
<div class="content">
<div class="category">
<li class='active'>Snare</li>
<li class='active'>High-hat</li>
<li class='active'>Base</li>
<li class='active'>Cymbal</li>
</div>
</div>
</div>
</div>
</main>
</div>
CSS
.category li {
display: inline-block;
margin-right: 1em;
}
Working version here: https://jsfiddle.net/fraggley/wrox5198/7/
If you are using bootstrap 4, you can use d-display-block class:
content{
width: auto;
position: fixed;
overflow: visible;
}
.category{
width: 200px;
display: inline-block;
float: left;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="d-flex two-column-wrapper" id="twocols-wrapper">
<main class="instruments-wrapper">
<div class="card bg-light col-md-6 offset-md-3">
<div class="card-header row align-items-center">
<h3 class="text-center"><?=$this->instrument->name?></h3>
</div>
<div class="content-wrapper">
<div class="content">
<div class="category">
<li class='active d-inline-block'>AAA</li>
<li class='active d-inline-block'>BBBB</li>
<li class='active d-inline-block'>CCCC</li>
<li class='active d-inline-block'>DDDD</li>
</div>
</div>
</div>
</div>
</main>
</div>

How can I change div's position when resizing?

I have a problem, all I want to do is at a certain width (using the #media) I want to change my left div to the right side under the one that is already there. I tried everything, including changing the display, positioning using left margin but due to the parent container it doesn't work. The only thing that I thought about is to make the same left div on the right side and to make the display to none, but I am pretty sure that's not the way to deal with it. I use Bootstrap 4.
This is the HTML:
.main{
background-color: #aaa;
box-shadow: 3px 3px 20px #000000;
border-radius: 20px;
margin-left: 20px;
margin-right: 20px
}
.left{
background-color: #aaa;
max-width: 200px;
height: 1%;
border-radius: 20px;
}
.right{
background-color: #aaa;
max-width: 200px;
height: 1%;
border-radius: 20px;
}
.right-content{
width: 100%;
text-align: center;
float: center;
margin-top: 10px;
}
.parent-container {
display: flex;
}
<div class="parent-container">
<div class="container left">
<div class="row">
Left content
</div>
</div>
<div class="container card main py-3">
<div class="container card">
<div class="card-body">
<div class="row">
<div class="col-lg-12 text-center">
<h2>TITLE2</h2>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<a href="#" class="link1">
<img src="2.jpg">
<h3>Title3</h3>
</a>
</div>
</div>
</div>
</div>
<div class="container right">
<div class="row">
<div class="right-content">
Right content here
</div>
</div>
</div>
</div>
To achieve the effect you want, you need to use Bootstrap 4 order-* classes. order-last in the code snippet below re-orders the column to come last by default but the order-md-first makes the column appear first on screens that are medium (md) or larger.
There are other ways of using the order classes to achieve the same result. This is just one of the possible options.
But there are many other and fundamental mistakes in your code. Here are a few pointers:
Do NOT nest containers inside other containers. Nest row-column pairs inside columns instead
Do NOT put any content directly into a .row. Bootstrap rows aren't designed for that. Put one or more columns (.col-*) into a row and put all your content inside that column(s).
Bootstrap 4 is flexbox-based by default and has classes to do almost everything you'll ever need in terms of positioning and spacing. Use those native Bootstrap classes instead of unnecessary custom css hacks.
Here's a working code snippet (click the "run code snippet" button below and expand to full page):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="container-fluid">
<div class="row">
<div class="col-12 col-md-3 col-xl-2 bg-light order-last order-md-first py-3">
Left div content <br>
Left div content <br>
Left div content <br>
</div>
<div class="col-12 col-md-9 col-xl-10 bg-primary py-3">
<div class="card py-3">
<div class="card-body">
<div class="row">
<div class="col text-center">
<h2>Right div TITLE</h2>
</div>
</div>
<div class="row">
<div class="col text-center">
<a href="#">
<img class="img-fluid" src="https://placeimg.com/888/88/tech">
<h3>Right div subtitle</h3>
</a>
</div>
</div>
</div>
<div class="row">
<div class="col text-center">
Right div content here
</div>
</div>
</div>
</div>
</div>
</div>
Notice: That code doesn't contain any of your custom css. If you want to add some custom css to that, start adding it line by line to see where your custom css breaks Bootstrap.
Also, the background classes bg-light and bg-primary in the code snippet above are just for making things easier to see.

How to align div to bottom inside div with Bootstrap?

html, body, .sidebar-container, .sidebar-row {
height: 100%;
}
.sidebar {
background-color: #2C3544;
}
#media (min-width: 992px) {
.sidebar {
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 1000;
display: block;
background-color: #2C3544;
}
}
img{
margin: auto;
display: block;
}
.sidebar-image{
margin-top: 15px;
}
.sidebar-items{
margin-top: 15px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid sidebar-container">
<div class="row sidebar-row">
<div class="col-md-2 sidebar">
<div class="container-fluid">
<div class="col-md-12 sidebar-image">
<img src="assets/logo-white.png" width="75px" height="75px"/>
</div>
</div>
<div class="row sidebar-items">
<div class="col-md-12">
<ul class="list-group">
<li class="list-group-item">Dashboard</li>
<li class="list-group-item">Projects</li>
<li class="list-group-item">Statistics</li>
</ul>
</div>
</div>
<div class="row align-bottom">
hafldjalfjsdlfsjdlfsjlfs
</div>
</div>
<div class="col-md-10 offset-md-2 content">
Main Content
</div>
</div>
</div>
I wrote this HTML/CSS code trying to align a div to the bottom inside another div:
I want to align this last div in the col-md-2 to the bottom of the sidebar-container which height is 100%. I tried adding the bootstrap class align-bottom but somehow this doesn't work. Could anyone help me out?
Suppose you have 2 divs. Div A(Outer) and Div B(Inner). To achieve your task just place Div B code in Div A code and in Div B css class add this
position : absolute
bottom : 0
You can also just use bootstrap flexbox to do this.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="d-flex align-items-start flex-column bg-success" style="height: 200px;">
<div class="mb-auto p-2">Flex item-1</div>
<div class="p-2">Flex item-2</div>
<div class="p-2">Flex item-3</div>
</div>
<div class="d-flex align-items-end flex-column bg-info" style="height: 200px;">
<div class="p-2">Flex item-a</div>
<div class="p-2">Flex item-b</div>
<div class="mt-auto p-2">Flex item-c</div>
</div>
align items to the left or right make sure that you include the entire d-flex align-items-end flex-column on the parent element and choose start or end depending if you want it to be aligned left or right.
align item to the bottom Then, use mt-auto on the div that you want to stick to the bottom of the parent.
When using Bootstrap grid system, my go-to solution is like this:
add d-flex to each col-*
add d-flex flex-column to each card-body
add mt-auto mx-auto to the last element (or last div of elements) I want to stick to the end
This prevents any further styling mess-up in my opinion.
Relevant Documentation:
Flex Alignment in Bootstrap 5.0: https://getbootstrap.com/docs/5.0/utilities/flex/#align-items
Vertical Alignment in Bootstrap 5.0: https://getbootstrap.com/docs/5.0/utilities/vertical-align/
Relevant Code:
What worked for me to align a div (of text) at the bottom of a row/container
<div class="d-flex align-content-end flex-wrap mb-2">
<span class="display-4 fw-bold text-black text-start mt-0 mb-0">Active Mural Projects</span>
</div>

Two left-floating cols plus right-floating sidebar Bootstrap

My goal is to achieve the following image on my page:
I managed to achieve this with the HTML and CSS you can find below, but it doesn't seem very viable, because the sidebar is losing it's physical height because of the position: absolute.
I'm wondering if it's possible to make one row with two columns on the left and a sidebar on the right, without having to use positioning.
I tried position: relative with a negative top, but since the top col-md-9 has a changing height (depending on what is entered), I can't give it a negative top. It'll simply be too static and impossible to maintain.
Changing the order in the HTML doesn't change anything, since the physical height of the sidebar will move the 2nd content down.
.sidebar {
position: absolute;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-9">
Changing content
</div>
<div class="col-md-3 sidebar">
Sidebar
</div>
<div class="col-md-9">
More content
</div>
</div>
I use xs columns for this example, but you can change to md in your page.
Firstly create a 9-column and a 3-column div. Then put two divs inside the 9-column one.
.content, .sidebar {
margin: 10px;
padding: 20px;
}
.content {
background-color: navy;
color: white;
}
.sidebar {
background-color: yellow;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row wrapper">
<div class="col-xs-9">
<div class="row">
<div class="col-xs-12">
<div class="content">Content</div>
</div>
<div class="col-xs-12">
<div class="content">Content</div>
</div>
</div>
</div>
<div class="col-xs-3">
<div class="sidebar">Sidebar</div>
</div>
</div>
You can nest col-x-x inside other col-x-x
You just have to create 2 parents: content and sidebar, then add multiple contents into the content parent :
<div class="row">
<div class="col-md-9">
<div class="col-md-12">
Content
</div>
<div class="col-md-12">
More content
</div>
</div>
<div class="col-md-3 sidebar">
Sidebar
</div>
</div>
You cannot have more that 12 columns in a row unless it is not defined in your custom grid.
What you can try is this:
<div class="row">
<div class="col-md-9">
<div class="row">
<div class="col-sm-12">
Changing content
</div>
<div class="col-sm-12">
More content
</div>
</div>
</div>
<div class="col-md-3" style="position: relative;">
<div class="row">
<div class="col-sm-12 sidebar">
Sidebar
</div>
</div>
</div>
</div
As a solution, you can make sidebar to stay at the right side of screen if you'll make left section overflow: auto.
.sidebar {
height: 100vh;
background: lightgreen;
}
.left-section {
height: 100vh;
background: lightblue;
overflow: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-9 left-section">
<div class="row">
<div class="col-sm-12">
Changing content
</div>
<div class="col-sm-12">
More content
</div>
</div>
</div>
<div class="col-sm-3 sidebar">
Sidebar
</div>
</div>
</div>