- This topic has 7 replies, 3 voices, and was last updated 10 years, 2 months ago by
Tom.
-
AuthorPosts
-
June 27, 2015 at 7:28 am #116896
Graham
I made some posts in my new blog and had left-aligned images, with the text flowing around them.
When I checked them on my mobile, the images were floating above the text as I expected, but they were left-aligned and there was no white space below them.
After many unsuccessful attempts to centre the images, I finally did it by setting the margins to auto. I also added 10px of padding beneath them, so the text wasn’t touching them.
Thought I’d share the code here in case others would like to use it. I put it in my child theme style.css
/* Aligning images in posts on mobiles */ @media (max-width: 768px) { .alignleft, .alignright { float: none; display: block; margin-left: auto; margin-right: auto; padding-bottom: 10px; } }Makes things much prettier I think.
June 27, 2015 at 12:34 pm #116960Tom
Lead DeveloperLead DeveloperThanks for posting! Thought this was done by default, will definitely add it into the theme 🙂
January 3, 2016 at 11:10 pm #163193xdaniel
Hello,
did this went into the standard code? On my sites the images in mobile view are still left aligned on top of post body/excerpt.
Is this a technical need or why can’t they have the same alignment as in desktop version?
Best wishes
Daniel
January 4, 2016 at 12:13 am #163198Tom
Lead DeveloperLead DeveloperHi Daniel,
There’s typically not enough room on mobile to keep the image floating left, so they shift to have their own row and should center.
Is that not happening for you?
January 4, 2016 at 12:57 am #163202xdaniel
Hello Tom,
yes it works with the code above.
I have a special blog page with deactivated featured image and allow some html in excerpt: http://notenschluessel-lev.de/aktuelles/
What I wanted was to center the images there, but not in the post itself?
Best wishes
Daniel
January 4, 2016 at 10:28 am #163302Tom
Lead DeveloperLead DeveloperYou could try something like this:
.masonry-post .entry-summary img { display: block; margin-left: auto; margin-right: auto; }January 4, 2016 at 12:09 pm #163341xdaniel
Yes, that worked better. Thanks a lot!
January 4, 2016 at 12:09 pm #163342Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.