Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CSS to align a button bottom of the screen using relative positions [closed]

Tags:

html

css

I need to position a button to the bottom of the screen. I need to use relative size and not absolute sizes, so it fits any screen size.

my CSS code:

position:relative;
left:20%;
right:20%;
bottom:5%;
top:60%;
like image 950
Sharon Watinsan Avatar asked Nov 28 '22 01:11

Sharon Watinsan


2 Answers

The below css code always keep the button at the bottom of the page

position:absolute;
bottom:0;

Since you want to do it in relative positioning, you should go for margin-top:100%

position:relative;
margin-top:100%;

EDIT1: JSFiddle1

EDIT2: To place button at center of the screen,

position:relative;
left: 50%;
margin-top:50%;

JSFiddle2

like image 104
Praveen Avatar answered Dec 09 '22 20:12

Praveen


This will work for any resolution,

button{
    position:absolute;
    bottom: 5%;
    right:20%;
}

http://jsfiddle.net/BUuSr/

like image 23
Chamika Sandamal Avatar answered Dec 09 '22 19:12

Chamika Sandamal