EN
CSS - center image inside div using flexbox
0 points
In this article, we would like to show you how to center image inside div using flexbox in CSS.
Quick solution:
xxxxxxxxxx
1
.container {
2
display: flex;
3
justify-content: center;
4
align-items: center;
5
}
In this example, we use flexbox to center the image inside the container
.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
.container {
7
height: 250px;
8
width: 250px;
9
border: 1px solid;
10
11
display: flex; /* <----- required */
12
justify-content: center; /* <----- required */
13
align-items: center; /* <----- required */
14
}
15
16
.image {
17
height: 100px;
18
color: white;
19
}
20
21
</style>
22
</head>
23
<body>
24
<div class="container">
25
<img class="image" src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
26
</div>
27
</body>
28
</html>