Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center an image in the middle of a div? [duplicate]

I need to center an image in a middle of a div.

<div class="main">
    <img...>
</div>

In the example below the image is centered, but not in the middle.

https://jsfiddle.net/web_garaux/tng7db0k/

like image 209
Daniel Avatar asked Jun 12 '17 13:06

Daniel


1 Answers

Simple and easy method to do this,

.test {
  background-color: orange;
  width: 700px;
  height: 700px;
  display:flex;
  align-items:center;
  justify-content:center;
}
<div class="test">
<img src="http://via.placeholder.com/350x150">
</div>
like image 200
codesayan Avatar answered Oct 20 '22 01:10

codesayan