-4

Can't figure how to center these 3 img elements horizontal

HTML

<!-- Homepage Content -->
<div id="center">

    <img src="images/homepage/wedding.png"/>
    <img src="images/homepage/wildlife.png"/>
    <img src="images/homepage/portrait.png"/>

</div> 

CSS

#center {
display:inline-block;
margin-left:auto;
margin-right:auto;
}

Fairly simple huh but it doesnt work! Test page

2
  • Specify div width and try to use margin: 0 auto; Commented Dec 17, 2014 at 2:24
  • use text-align: center for your #center Commented Dec 17, 2014 at 2:25

1 Answer 1

3

You just need to add text-align: center for your #center

<div id="center">

   <img src="images/homepage/wedding.png"/>
   <img src="images/homepage/wildlife.png"/>
   <img src="images/homepage/portrait.png"/>

</div> 

CSS

#center{
  display: block;
  padding: 20px;
  text-align: center;
  border: 1px solid #000;
}
#center img{
  display: inline;
}

Check this link to see demo.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.