how to move div to center of page code example
Example 1: css center element on screen
.centered {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Example 2: center div in middle of page
.centered {
position: fixed;
top: 50%;
left: 50%;
/* bring your own prefixes */
transform: translate(-50%, -50%);
}
Example 3: how to put container in center of page
#container
{
width: 400px;
margin-left: auto;
margin-right: auto;
}
Example 4: css center text
/* To center text, you need to use text-align. */
.centerText {
text-align: center; /* This puts the text into the center of the
screen. */
}
/* There are also other things that you can use in text-align:
left, right, and justify. Left and right make the test align to the
right or left of the screen, while justify makes the text align both
sides by spreading out spaces between some words and squishing others. */
Example 5: align div to center of screen
div.the-center-div {
margin: 0 auto;
}
Example 6: center text in div container
text-align: center