2

I got a div container that has a max height of 400 pixels. I'm placing a pretty large image inside the container. Since the container has a max height it's obviously cutting off most of the picture, which is what I'm aiming for. But my only issue is trying to get the image to center inside the div, so the main part of the picture is shown.

Here is the code I have currently:

<div class="headerimg">
<img src="www.jpg.com"/>
</div>

.headerimg { max-height: 400px; overflow: hidden; }
.header img { width: 100%; height: auto; }
Dondada
  • 421
  • 9
  • 25

2 Answers2

2

Try using:

div.container {
    margin: 0 auto;
    width: 900px;
}
div.container img {
    max-height:400px;
}
RealDeepak
  • 823
  • 6
  • 9
0

Simple use : text-align:center

live example is here >>>>

div{
  max-height:400px;
  border:1px solid red;    
  text-align:center;
}
div img{
  height:500px;
  width:200px;
}
Pedro Estrada
  • 2,384
  • 2
  • 16
  • 24
Suraj Rawat
  • 3,685
  • 22
  • 33