WordPress.org

Support

Support » Themes and Templates » How to center images?

How to center images?

  • 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..
    Thanks!
    Greetings from Argentina!

Viewing 9 replies - 1 through 9 (of 9 total)
  • <center>image code here</center>

    that worked for me..let me know 🙂

    Do you have a link for your site?

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

    esmi

    @esmi

    Forum Moderator

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

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

    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.

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

    Cheers,
    Matty.

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

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

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

    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.
    Daniele
    if you’d like to see what I mean, visit:

    Risorse interattive di matematica

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to center images?’ is closed to new replies.
Skip to toolbar