Archived topic
Aligning images in single posts
5 replies · Started by Erika on May 20, 2021
Hi there,
I know, a very basic question, but can you help me out with it?
I would like to align ALL images in all single posts with a few lines of css instead of aligning each one in the block editor.
I have this css, but it does not work:
img.single-post {
display: block;
margin-left: auto;
margin-right: auto;
}
The selector must be wrong, but I can´t figure out the right one.
Thank you! Erika
Hi Erika,
Are you trying to align all of them to the center?
If so can you make sure they are not wrapped in a <p> tag?
The post I checked wasn't using the block editor.
This should work if you are using the block editor:
body.single .wp-block-image {
text-align: center;
}
Let me know if this helps :)
Hi Leo,
you are right. I just deactivated Elementor Pro and I am switching to Elements with GenerateBlocks. Obviously the older posts were put into the classic editor. I was not aware of that.
Thank for spotting it! Funny enough, yesterday I had a very similar code to yours :) and it worked on one, but I could not find why it way not working on other. :D
Thank you! Erika
No problem :)
