<div class="container">
<div class="div-to-center">
<h2>Center me</h2>
<p>Easy with Flexbox!</p>
<img src="https://www.thediygolfer.com/wp-content/uploads/2020/12/putting-1200x800.png" width="200" alt="">
</div>
</div>
.container {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.div-to-center {
max-width: 250px;
}
/*
Style only properties - these do not affect
the positioning of the container
*/
.div-to-center {
padding: 20px;
border: 1px solid grey;
border-radius: 5px;
color: #BFA38A;
background-color: #1D2326;
}
h2 {
margin: 0;
}
img {
border-radius: 5px;
box-shadow: 1px 2px 3px 1px rgba(0,0,0,0.2);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.