Jump to content

How to align an image to the center?


Norman

Recommended Posts

I think you have not understood how to center an element.For an inline element, such as <img>, you should define the style of its parent element:

<div class="imgBox"><img src="test.jpg" width="200px" height="100px" alt="test" /></div>div.imgBox{[b]text-align:center;[/b]}

For a block element, such as <table>, you should define the style of itself:

<table class="center">.......</table>table.center{width:300px;/*It should be less than its parent*/ [b]margin:0 auto;[/b]}

However, you could change an inline element into a block element. Then, you can define its style as a block element.

<div class="imgBox"><img class="center" src="test.jpg" width="200px" height="100px" alt="test" /></div>img.center{display:block;margin:0 auto;/*Its width should be less than its parent*/ }

You can have a try. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...