In my project, I have a collection of div
elements that need to be spaced vertically from one another by the height of the window plus an additional 100px. However, I encountered a discrepancy when setting this margin using jQuery between mobile and desktop browsers. The issue seems to be related to how the additional + 100
is interpreted as a string rather than a number.
Snippet of My Code
$(".text-container").css("margin", "50px auto " + (window.innerHeight + 100) + "px auto")
Observed Margin on DESKTOP (Chrome)
alert((window.innerHeight + 100) + ", " + typeof (window.innerHeight + 100) + ", " + $(".text-container").css("margin"))
--> 740, number, 50px 18px 740px
Observed Margin on MOBILE (Chrome and Samsung Internet)
alert((window.innerHeight + 100) + ", " + typeof (window.innerHeight + 100) + ", " + $(".text-container").css("margin"))
--> 874, number, 50px 20.6094px 740100px 20.5938px
It seems like there's some misunderstanding in my implementation. Any insights on what might be causing this difference?