/    Sign up×
Community /Pin to ProfileBookmark

Problem with mobile page height

Hi,
I am making an adaptive page using CSS. I have a trouble with the mobile version that the vertical position of the elements in the page varies from phone to phone. I’ve managed the page to look all right on my Blackberry and on iPhone, but on Samsung it’s complete mess.
The code I use is like this:

“`
body {
background: url(bgr-vertical.jpg);
background-repeat: no-repeat;
background-size: 100%;
width: 100%;
padding-top: 300%;
}

#firstcolumn {
position: absolute;
top: 74%;
left: 5%;
width: 90%;
height: 15.5%;
}

“`

The body tag sizes the page according to the background image, which has an aspect ratio 1×3. Then I position other elements, like <div id=”#firstcolumn”>, etc. So, for each phone the vertical positions appear different. For Blackberry and iPhone they are approximately the same but in Samsung phones everything gets shifted.
What would be a good way to make everything look the same on all phones?
And a related question, how are these % calculated in top: 74%; ? I would expect this to be % of the <body> height (as <body> is the ancestor for this <div> element), but for the lowest element I had to set top: 200%; So, as the values can be above 100%, it should be the percentage of something else, not of the <body> height?

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumFeb 01.2023 — @ldor108#1650360
>Then I position other elements, like <div id="#firstcolumn">

As visible from the CSS you are doing this by positioning the elements absolutely. This is a reason for trouble very often, don't do so.

Instead make yourself familiar with flex and grid layout, using these makes it easy to make responsive layouts:

https://css-tricks.com/snippets/css/complete-guide-grid/

https://css-tricks.com/snippets/css/a-guide-to-flexbox/

If you run into difficulties, come back and ask.
Copy linkTweet thisAlerts:
@ldor108authorFeb 01.2023 — Thank you, I will go through it
×

Success!

Help @ldor108 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...