Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute bottom position in scroll div?

Tags:

html

css

Fiddle

I wish to align my buttons to the base of the container so I use:

.buttons{
    position: absolute;
    bottom: 0;
}

This is fine for when there is not much content (the pink div in the fiddle), but when there is a lot of content (the orange div in the fiddle), the container scrolls and the buttons are not at the bottom of the container.

How can I have it so that the buttons are at the bottom of the container when it doesn't have a lot of content and they are at the bottom of the scroll (below the content) when there is a lot of content.

like image 438
panthro Avatar asked May 19 '15 14:05

panthro


People also ask

How to set the position of the <div> element at the bottom?

Set the bottom edge of the <div> element to 10px above the bottom edge of its nearest parent element with some positioning: The bottom property affects the vertical position of a positioned element.

How does position absolute work in CSS?

CSS position absolute | How does position absolute work in CSS? The CSS absolute is the value for position property. This position property is used to sets how an element is positioned in the document. An element with position: absolute is arranged relative to the nearby positioning element.

Why do absolute elements move horizontally when scrollbar is removed?

If they are inside the overflow area, then the absolute elements will naturally move horizontally when a scrollbar is introduced or removed. However, if they are outside of the scrolling area, then you run the risk of "right:0px" overlapping with the scrollbar of the viewport.

What is absolute position in Revit?

position: absolute; An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.


2 Answers

I added an .inner container that has a min-height. If the content in there is low, then the .inner container will push your buttons to the bottom. If the content is more, then the .inner container will grow along.

.inner {
    min-height: 149px;
}

Also note that the buttons have a position relative instead of absolute. When an element is absolute, it does not react to the page contents.

https://jsfiddle.net/76gbfrah/10/

like image 92
Davy Avatar answered Oct 24 '22 11:10

Davy


You have to add height:100%to html and body and then min-height:100%to your container like this (I have added a few more lines to make it look better):

body, html {height:100%; margin:0;}

* {box-sizing: border-box;}
.container{
    min-height: 100%;
  position: relative;
    padding-bottom:30px;
}
p {margin:0;}

.buttons{
    position: absolute;
    bottom:0;
}

.pink{
    background: pink;
}

.tomato{
    background: tomato;
}

Here you have the FIDDLE

(add more content to check it out)

EDITED (fixed height) Same concept just adding another container to use the min-height

NEW FIDDLE

like image 28
Alvaro Menéndez Avatar answered Oct 24 '22 11:10

Alvaro Menéndez