Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stacking Divs from Bottom to Top

People also ask

How do you stack a div on top of another div?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

How do you stack elements in a div?

Position the outer div however you want, then position the inner divs using absolute. They'll all stack up.


All the answers miss the scrollbar point of your question. And it's a tough one. If you only need this to work for modern browsers and IE 8+ you can use table positioning, vertical-align:bottom and max-height. See MDN for specific browser compatibility.

Demo (vertical-align)

.wrapper {
  display: table-cell;
  vertical-align: bottom;
  height: 200px;
}
.content {
  max-height: 200px;
  overflow: auto;
}

html

<div class="wrapper">
  <div class="content">
     <div>row 1</div>
     <div>row 2</div>
     <div>row 3</div>  
  </div>
</div>  

Other than that, I think it's not possible with CSS only. You can make elements stick to the bottom of their container with position:absolute, but it'll take them out of the flow. As a result they won't stretch and make the container to be scrollable.

Demo (position-absolute)

.wrapper {
  position: relative;
  height: 200px;
}
.content {
  position: absolute;
  bottom: 0;
  width: 100%;
}

A more modern answer to this would be to use flexbox.

As with many other modern features, they won't work in legacy browsers, so unless you're ready to ditch support for browsers from the IE8-9 era you will need to look for another method.

Here's how it's done:

.parent {
  display: flex;
  justify-content: flex-end;
  flex-direction: column;
}

.child {
  /* whatever */
}

And that's all you need. For further reading on flexbox, see MDN.

Here's an example of this with some basic styling: http://codepen.io/Mest/pen/Gnbfk


We can simply use CSS transform to archive this.

I created a codepen for it. https://codepen.io/king-dev/pen/PoPgXEg

.root {
  transform: scaleY(-1);
}
.root > div {
  transform: scaleY(-1);
}

The idea is to flip the root first horizontally and then flip direct children divs again.

NOTE: the above method also reverses the order of divs. If you simply want to place them to start from bottom you can do the following.

.root {
  display: flex;
  flex-direction: column;
  height: 100px;
  overflow-y: auto;
}
.root > div:first-child {
  margin-top: auto;
}

i want this work with bootstarp like chatting app where message flow bottom to up

after reading stuff , i found this

i have a outer div assume class .outerDiv and then UI , list

.outerDiv {
    height: 361px;
    position: relative;
}
ui.msg-content{
    width: 100%;
    bottom: 0;
    position: absolute;
    max-height: 98%;
    overflow-y: auto;
}

enter image description here

enter image description here