Answers for "how to align elements set in center of container"

CSS
37

how to center a div in css

.center {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
Posted by: Guest on March-31-2021
2

how to center a div in css

/* Assume the div has a class of "center"
   The below would center it horizontally
*/
.center {
	margin-left: auto;
    margin-right: auto; 
}

/* There is a shorthand and it is given below */
.center {
	margin: 0 auto; 
}
Posted by: Guest on January-24-2022

Code answers related to "how to align elements set in center of container"

Browse Popular Code Answers by Language