Assuming you have an HTML file created and a CSS file, create a div. Give it a class or an ID.
Style the display property to "flex." Then define the align-items and justify-content property to “center.”
<!DOCTYPE html>
<html>
<head>
<title>TO CENTER A DIV </title>
</head>
<style>
.center{
display: flex;
align-items: center;
justify-content: center;
}
</style>
<h2>center a div</h2>
<div class="center"><button>center the div</button></div>
</body>
</html>
Top comments (2)
Doesn't matter who we are, we must know how to center a div. Therefore, all web developers must be thankful to you.
One of legendary question xD.