-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove margin from body on mobile #950
base: master
Are you sure you want to change the base?
Conversation
Most browsers have a default margin of 8px on the `body` element, which was offsetting the `canvas` element. This was not only pushing the canvas slightly off screen, but was also affecting the calculation of touch coordinates (which was most noticable with the PuzzleScript Plus fork because it supports touch controls).
I do also have code that I think makes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, pending a question.
@@ -161,7 +161,7 @@ | |||
} | |||
|
|||
.tab-icon { | |||
left: -0.5em; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the intent behind this change? To account for the slight shift in the margin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right! The tab icon was being positioned relative to the inside of the margin, so to make up for the 8px margin, it was being shifted back 8px (0.5em is equivalent in most browsers by default if you don't change the font size). So now that the margin is gone, it doesn't need to be shifted. Without this, the little pull out tab thing doesn't stick out enough.
By default, most browsers apply a default margin of 8px to the
body
element. On mobile, PuzzleScript applies the following style thebody
element:The
position: "fixed"
creates a new document flow root, which means that any children withposition: absolute
are going to be positioned with the 8px offset, including the game canvas.This can be seen by simulating a mobile device (or using a real mobile device) and inspecting the body and game canvas elements (note the orange margin at the top and left):
Here's another example where I've set the viewport size so that the game should fit perfectly on the screen, but you can see everything is offset slightly:
This caused two issues:
relMouseCoords
ininputoutput.js
were offset by 8px. This was most noticeable when using the PuzzleScript Plus fork with support for touch controls.The fix is just to set the
body
margin to 0 and make sure the mobile pull-out menu is still positioned correctly. After the fix, the above game fits on screen as expected: