Jump to content

Recommended Posts

Posted

I am trying to centre an image using the following css

 

img.center {

display: block;

margin-left: auto;

margin-right: auto;

}

 

followed by the html

 

Where to find us

 

but the image sticks resolutely to the left.

 

What am I doing wrong please?

Posted

It's probably because the p tag that it's inside is only using as much width as it needs so the image in centering in a space which is just the same width and set on the left.

 

Add a width: 100%; to the p tag and see if that cures it.

 

Where to find us

 

and just for safety add the image width and height to the class:-

img.center {

display: block;

margin-left: auto;

margin-right: auto;

width: 450px; height: 319px;

}

Posted

Discovered the problem is that the text for the div is set to justify, so won't allow the picture to centre. It does centre with Wickams method though, but that would mean having to set the css for other pictures that I would wish to centre.

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...