metadata Posted August 6, 2012 Share Posted August 6, 2012 I'm trying to align an image in my HTML document to the center of the page. In looking through the references on the W3 page I see that the align attribute is deprecated. There's a note that the CSS float property can be used (I am using an external style sheet) but it looks like it would only set things to the right or left, but not the center. Can someone point me in the direction of where I can look to solve this? Thanks Link to comment Share on other sites More sharing options...
saveyourself91 Posted August 6, 2012 Share Posted August 6, 2012 Give your image a width and then use margin:auto; Link to comment Share on other sites More sharing options...
metadata Posted August 6, 2012 Author Share Posted August 6, 2012 When use auto it stays on the left side. I've been trying different percentages and that seems to work better. Link to comment Share on other sites More sharing options...
niche Posted August 6, 2012 Share Posted August 6, 2012 Make that margin: 0 auto. Link to comment Share on other sites More sharing options...
metadata Posted August 6, 2012 Author Share Posted August 6, 2012 Make that margin: 0 auto. that doesn't seem to be working, is my code correct in my CSS? img {margin:0 auto;} Link to comment Share on other sites More sharing options...
dsonesuk Posted August 6, 2012 Share Posted August 6, 2012 By default the img element is a inline element, margin: 0 auto; width: ###px; won't wotk unless you define it as block element. img {margin:0 auto; width: ###px; display:block;} 2 Link to comment Share on other sites More sharing options...
metadata Posted August 6, 2012 Author Share Posted August 6, 2012 OK, that worked perfectly. Thanks! Link to comment Share on other sites More sharing options...
niche Posted August 6, 2012 Share Posted August 6, 2012 This will give you additional background for future display decisions: http://www.w3schools.com/jsref/prop_style_display.asp Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now