Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align DIV to bottom of the page

Tags:

html

css

I have a DIV that needs to be aligned to the bottom of a search result page, problem is whenever there is no search result or less rows of search result displayed on the page, the DIV goes up from the bottom of the page.

enter image description here

but it should be placed like this

enter image description here

and whenever there are more rows and the page can be scrolled down, the DIV should be place like this.

enter image description here

My currrent code looks like this

        <div id="bottom-stuff>              <div id="bottom">                              // DIV stuff             </div>          </div>   #bottom-stuff {     padding: 0px 30px 30px 30px;     margin-left:150px;     position: relative; }  #bottom{      position: absolute; bottom: 0px;  } 
like image 378
Naveen Gamage Avatar asked Dec 04 '13 08:12

Naveen Gamage


People also ask

How do I position something at the bottom of a page in CSS?

If position: absolute; or position: fixed; - the bottom property sets the bottom edge of an element to a unit above/below the bottom edge of its nearest positioned ancestor. If position: relative; - the bottom property makes the element's bottom edge to move above/below its normal position.

How do I make the div stick to the bottom of the footer?

First set the min-height of body to 100vh. min-height: 100vh; . Set the body display to flex display: flex; and flex-direction to column flex-direction: column; . Select footer element (of whatever you want to stick to bottom) and set top margin to auto margin-top: auto; .


2 Answers

Right I think I know what you mean so lets see....

HTML:

<div id="con">    <div id="content">Results will go here</div>    <div id="footer">Footer will always be at the bottom</div> </div> 

CSS:

html, body {    margin:0;    padding:0;    height:100%; } div {     outline: 1px solid; } #con {    min-height:100%;    position:relative; } #content {    height: 1000px; /* Changed this height */    padding-bottom:60px; } #footer {    position:absolute;    bottom:0;    width:100%;    height:60px; } 

This demo have the height of contentheight: 1000px; so you can see what it would look like scrolling down the bottom.

DEMO HERE

This demo has the height of content height: 100px; so you can see what it would look like with no scrolling.

DEMO HERE

So this will move the footer below the div content but if content is not bigger then the screen (no scrolling) the footer will sit at the bottom of the screen. Think this is what you want. Have a look and a play with it.

Updated fiddles so its easier to see with backgrounds.

like image 144
Ruddy Avatar answered Oct 09 '22 02:10

Ruddy


Try position:fixed; bottom:0;. This will make your div to stay fixed at the bottom.

WORKING DEMO

The HTML:

<div id="bottom-stuff">   <div id="search"> MY DIV </div> </div> <div id="bottom"> MY DIV </div> 

The CSS:

#bottom-stuff {      position: relative; }  #bottom{      position: fixed;      background:gray;      width:100%;     bottom:0; }  #search{height:5000px; overflow-y:scroll;} 

Hope this helps.

like image 20
Nitesh Avatar answered Oct 09 '22 03:10

Nitesh