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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...