Answers for "center an absolute div horizontally"

6

css absolute center horizontal

.parent{  position: relative;}.child{  position: absolute;  top: 50%;  left: 50%;  transform: translate(-50%, -50%);}
Posted by: Guest on July-14-2020
0

position absolute horizontally center

/*if you want to align center on left attribute.
The same thing is for top alignment, you could use margin-top: (width/2 of your div), the concept is the same of left attribute.
It's important to set header element to position:relative.
try this:
*/
#logo {
    background:red;
    height:50px;
    position:absolute;
    width:50px;
    left:50%;
    margin-left:-25px;
}

/*If you would like to not use calculations you can do this:*/

#logo {
  background:red;
  width:50px;
  height:50px;
  position:absolute;
  left: 0;
  right: 0;
  margin: 0 auto;
}
Posted by: Guest on September-23-2021

Code answers related to "center an absolute div horizontally"

Browse Popular Code Answers by Language