position absolute horizontally center

Solutions on MaxInterview for position absolute horizontally center by the best coders in the world

showing results for - "position absolute horizontally center"
Anthony
02 May 2016
1/*if you want to align center on left attribute.
2The same thing is for top alignment, you could use margin-top: (width/2 of your div), the concept is the same of left attribute.
3It's important to set header element to position:relative.
4try this:
5*/
6#logo {
7    background:red;
8    height:50px;
9    position:absolute;
10    width:50px;
11    left:50%;
12    margin-left:-25px;
13}
14
15/*If you would like to not use calculations you can do this:*/
16
17#logo {
18  background:red;
19  width:50px;
20  height:50px;
21  position:absolute;
22  left: 0;
23  right: 0;
24  margin: 0 auto;
25}