AM
6
Why is email not centered on Android 4.4?
I'm not actually sure what's going on. The email looks like it has some margin or padding on the left. Therefore, the email doesn't look centered. It looks shifted to the right and it's cropping a small portion of the right side of the email.
Anyone have any ideas as to what is going on here?
Problem solved!
https://blog.jmwhite.co.uk/2015/09/19/revealing-why-emails-appear-off-centre-in-android-4-4-kitkat
Add this to your
head
CSS and see if removes the margin.Due to the lack of
id
orclass
, you can't target thatdiv
wrapper specifically without using attribute selectors (and even with that its a hack), thebody
is the main area to neutralise because its the element creating the side margin, thediv
creates additional and potentially unwanted margin on the top and bottom as well. See below for the explanation of what's going on.Delicious Source Code
After some source code diving into the Android 4.4 email app (which due to Android being Open Source is rather easy!), I've found the cause of this. This is an actual function in one of the many Java classes, specifically part of the
SecureConversationViewController.java
file.Note how the wrapping
body
tag has been defined, there is alsodiv
withmargin:16px 0;
applied. This appears to match the behaviour we are seeing with all sides except the right having margins. Except, the shorthand written in the code should be only applying it to the top and bottom, having0
declared for the right side means the same value should be used for the left right? Correct, because the wrapperdiv
isn't causing the side margin, thebody
tag is. Notice the%s
, that's a placeholder for apx
value which is calculated during rendering the message view, the side margin is actually being applied there.The technical stuff
This is the actual Java source code where the
body
anddiv
wrapper is generatedAndroid 4.4 body and wrapper
Side margin calculation
In addition, this Java file also contains a variable value which is based on a certain calculation of two values.
This is where the additional margin value is coming from, it is based on an Offset divided by Destiny, which will vary based on each device.
http://developer.android.com/reference/android/content/res/Resources.html#getDimensionPixelOffset%28int%29
http://developer.android.com/reference/android/content/res/Resources.html#getDisplayMetrics%28%29
http://developer.android.com/reference/android/util/DisplayMetrics.html#density
I love this fix and have been using it for some time, however when testing this week my emails are cutting off on the right again with spacing on the left. [booooooo] Have you heard of any changes?
I have been having the same issue.
Thank you for taking your swiss army knife and cutting open email clients like this! I've just dropped in your code and can confirm that it works! Cheers James!
Nice one for all the research and great solution.
Awesome fix! Thanks for the tip!
Well done James! This fixed my issue!
This solution doesn't appear to be working anymore. Does anyone have an alternative?
I've noticed this as well. The original link by OP is 404, but I think this what is being referred to:
Top and Left side:
Right side:
Bottom side:
Using a bit of selector magic with CSS you can see where the space is coming from visually:
The pink outer colour is the space Android 4.4 is adding, the next inner layer is the padding of the actual email template.
The padding/margin appears to be added to the top, left and bottom sides. The fact this is happening on the left side without being equally set on the right side is causing the problem and makes the email overall slightly off centre. This is obviously being done by some form of wrapping element within the email client. I'm not sure at this point what that is and if it can be overruled by some CSS or layout change.
Like Nicole, investigation ongoing!
Edit #1: Appears to be some form of
div
element. Using a rather generic and global CSS rulediv { margin:0 !important; padding:0 !important; }
, this removed the top and bottom additional margin/padding, the left side still remained however. Further work is needed to try and find out what specific elements are in use and if anyid
orclass
can be used to specifically target Android 4.4Edit 2: See my other post which exposes where the issue is happening in the email app source code
You are a magician! Thanks so much for working all this out! I am eternally grateful.
Two things did it for me:
body { margin: 0 !important; padding: 0; ... }
body > div { margin:0 !important; } /*was enough to remove the space above*/
This solution appear not to be working anymore, I tried everything and nothing works.
Not found dear
I added negative margin, which fixed the issue. Try adding to your wrapper or body tag margin: -20px !important; padding: 0 !important;
I have had this issue since the upgrade from 4.2 to 4.4 in litmus but haven't investigated.
I can't access the results at your link, but I think I know what you're talking about. It's like the body has margin or padding on it that cannot be removed (kinda like Outlook 2007/10/13).
I've tried so many different things to get rid of this: zeroing margins, zeroing padding, using min-width, trying 0px -webkit-margin-before/after/start/end, all to no avail.
My attempts are ongoing!
Excellent
my experience is that Google changed the way the client renders HTML. From what I've read/heard is that they're trying to migrate the platform into Gmail, thus it has some querks(like Gmail)
The fix is pretty simple, but have a major impact on how I do emails and thus I haven't myself implemented this myself because I think it's stupid and counterproductive in the end (as they will probably change it again soon in the future)
The fix:
Instead of writing your mobile responsive code like break classes, width and so, on TD's, you have to write it on Tables. That basically means each time you have 2 blocks you want to seperate on mobile, you have to incase them both in Tables and write the mobile responsive code on these specific tables.