- This topic is empty.
-
AuthorPosts
-
February 12, 2014 at 3:20 am #162660
j05hr
ParticipantHi
I’m using Chris’s method to vertically align an image inside a parent div. It all works fine apart from on mobile it won’t center on a mobile browser. I’m not sure if it works on IOS as I can only test on an Android device.
If I make the browser from a desktop the same size as the mobile browser it works fine so I can only assume display: table-cell is in some way defunct on mobile.
Does anyone have any experience of making this work for mobile?
Thanks
February 12, 2014 at 3:41 am #162661Paulie_D
MemberHmm…seems to be OK according to CanIUse.com : http://caniuse.com/#search=table-cell
Looking…
February 12, 2014 at 3:50 am #162663Paulie_D
MemberActually, it’s not centering the images on desktop either (Chrome 32).
The issue seems to be the class
.bestSellerImg
..bestSellerImg { display: table-cell; text-align: center; vertical-align: middle; width: 195px; height: 205px; border: 1px solid #bfbfbf; margin: 0 auto; }
This is NOT centering the div inside the divs with a class of
.bestSellerContainer
[at least on desktop]. Changing the display mode to block DOES center the div but it stops the image being aligned vertically.I’ll have to think some more…
February 12, 2014 at 3:55 am #162664j05hr
ParticipantYeah the function works as in it will center vertically but it won’t center to the page if that makes sense.
Edit: Just seen your reply, that’s good to know it isn’t working in Chrome, I had only checked Firefox which was fine. It must be something in my responsive code then.
February 12, 2014 at 4:09 am #162666Paulie_D
MemberOne thing you could do is (for mobile) is change the
.bestSellerImg
width to 100%, change thedisplay
property toblock
and remove the border.The image will center horizontally (but not vertically) but there would be no visual reference to seeing the the image is not aligned vertically…if you see what I mean.
February 12, 2014 at 4:13 am #162667j05hr
ParticipantYeah I was thinking of doing that, there isn’t many other options unless changing the whole approach. Am I right in thinking it’s that it doesn’t like the percentage width?
February 12, 2014 at 4:14 am #162668Paulie_D
MemberI had only checked Firefox which was fine. It must be something in my responsive code then.
Hmmm…It could be how the media queries are structured. Are you using min and max widths, it didn’t look like it.
February 12, 2014 at 4:21 am #162670j05hr
ParticipantJust max width. I’m not sure now if it’s browser specific or just an error on might part in the code.
February 12, 2014 at 4:39 am #162673Paulie_D
MemberAt a quick glance your media queries are overlapping
You have several max-widths but with no min-widths the largest would always apply.
I can’t be sure on the monitor I am using at the moment but Chrome is applying the @540px query and FF is not, it’s using the @1024px query (number approx).
February 12, 2014 at 6:54 am #162685j05hr
ParticipantEven with them overlapping could that be the problem?
I think even at the desktop size it isn’t centered it just looks it because the images are so close to eachother.
February 12, 2014 at 7:44 am #162691Paulie_D
MemberI think even at the desktop size it isn’t centered it just looks it because the images are so close to eachother
Exactly…unfortunately this might mean re-thinking the whole layout approach.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.