How to center images? (10 posts)

  1. matiasc
    Posted 6 years ago #

    Hi people, my question is simple, ever since I started using P2 I can't center images on the posts.
    How can I solve it? I've tried everything, I think..
    Greetings from Argentina!

  2. ptcounterpt
    Posted 6 years ago #

    <center>image code here</center>

    that worked for me..let me know :)

  3. monodistortion
    Posted 6 years ago #

    Do you have a link for your site?

    <center> tags may work if you don't mind that they are invalid for XHTML strict.

  4. esmi
    Forum Moderator
    Posted 6 years ago #

    <center>? Bleurgh...

    The theme probably just need a CSS tweak. A site url would help to confirm it and enable a fix to be suggested.

  5. noel
    Posted 6 years ago #

    You just need to edit the CSS a bit for how you'd like images displayed.

  6. miocene22
    Posted 6 years ago #

    for the image to be centered use this css:

    .centerimg {margin-left:auto; margin-right:auto;}

    For the parent container (e.g. the div containing the image - use

    .parentdiv {text-align: center;}

    Note: the above code will center everthing within the parent div that you specify. To center only an image make a div that contains only the image.

    margin-left:.... should work for most browsers.

  7. Matty Cohen
    Posted 6 years ago #

    Hi matiasc,
    I use the following line in my CSS file for centering images:

    .aligncenter, img.aligncenter { clear: both; display: block; margin-left: auto; margin-right: auto; }

    The above code will use the class that is applied to images when selecting the centre alignment in the WordPress image edit window in the backend. This does similar work to the code mentioned by miocene22, while making use of a native WordPress class.

    I hope this helps. :)


  8. neononcon
    Posted 6 years ago #

    @mattyza the code you gave works perfectly! Thanks for this thread...

    .aligncenter, img.aligncenter { clear: both; display: block; margin-left: auto; margin-right: auto; }

  9. jimcoe
    Posted 6 years ago #

    mattyza --> Thanks! centering images now works perfectly with the built-in image editing "Center" button. Very nice!

  10. passegua
    Posted 6 years ago #

    Hi everybody, my problem was centring an image WITHOUT text wrapped around it.
    I was able to do it easily when I used Windows Live Writer, but now I am happy to use a MacBook and I sincerely miss Windows Live Writer (btw do you know anything as good as that?).

    Well now I tried to centre the image using the wordpress editor, not so bad at all, but even if I tag the image "center" or "aligncenter" then the image will be always wrapped around by the text and I do not like that.

    After a few trials I copied what Windows Live Writer put and I discovered that it adds this piece of code:
    display: block;
    where? in the "advanced" options of the image on the line Style!
    So now I am happy! I can use my MacBook and I can centre images WITHOUT any text around.
    if you'd like to see what I mean, visit:

Topic Closed

This topic has been closed to new replies.

About this Topic