I have a div
with some children:
<div class="content">
<h1>heading 1</h1>
<h2>heading 2</h2>
<p>Some more or less text</p>
<a href="/" class="button">Click me</a>
</div>
and I want the following layout:
-------------------
|heading 1 |
|heading 2 |
|paragraph text |
|can have many |
|rows |
| |
| |
| |
|link-button |
-------------------
Regardless how much text is in the p
I want to stick the .button
always at the bottom without taking it out of the flow. I've heard this can be achievable with Flexbox but I can't get it to work.
You can use auto margins
So you can use one of these (or both):
Alternatively, you can make the element before the
a
grow to fill the available space:You can use display: flex to position an element to the bottom, but I do not think you want to use flex in this case, as it will affect all of your elements.
To position an element to the bottom using flex try this:
Your best bet is to set position: absolute to the button and set it to
bottom: 0
, or you can place the button outside the container and use negativetransform: translateY(-100%)
to bring it in the container like this:Check this JSFiddle
The solution with
align-self: flex-end;
didn't work for me but this one did in case you want to use flex:CSS
HTML
Results in:
Try This
To your use case, just this will do the job
You can do something like this if you want to stick button to the bottom of the screen
codepen