~~Solutions to fix sections moving on mobile view

πŸ˜€ Hi y all , some time ago I ve seen on my YT feed a video posted by Kevin πŸ”΄ where he fixed the moving of sections on the body while scrolling in mobile πŸ”Ί , does somebody know the link for that ? or the solutin either one of thouse could really help πŸ“—
19 Replies
Kevin Powell
Kevin Powellβ€’6mo ago
I don't know the specific video, but I'm guessing I used either position: fixed or position: sticky
Beyond^sight
Beyond^sightOPβ€’6mo ago
@Kevin Powell Oh my bad, let me rephrase it, how can I stop the sections from moving on Y axe while scrolling ?
Chris Bolson
Chris Bolsonβ€’6mo ago
As Kevin says, position: fixed or position: sticky. In general terms "fixed" will fix the element to the viewport and not move while scrolling. This is often used for a header that you want to remain visible at the top all the time. "sticky" is similar, however in this case it will be "stuck" to it's nearest ancestor element that has a position absolute or relative. The difference is that, once that parent element scrolls out of view, the "sticky" element will also scroll out with it.
Beyond^sight
Beyond^sightOPβ€’6mo ago
ah that makes sense now, I had a vision that sections will move with the scroll if I ll do that LOL I tried both positions but the sections still move up while I scroll up in the mobile........
Lamer of Sweden
Lamer of Swedenβ€’6mo ago
Could you use https://codepen.io or similar to demonstrate?
CodePen
An online code editor, learning environment, and community for front-end web development using HTML, CSS and JavaScript code snippets, projects, and web applications.
Chris Bolson
Chris Bolsonβ€’6mo ago
you need to set the actual position, eg. top: 0
Beyond^sight
Beyond^sightOPβ€’6mo ago
top: 0; will set the section at the top of their actual position in app or in the top of app ? I did top: 0; for all comp and tried with both positons , but that only makes them stick to the top of the viewport and it makes them overlap eachother
Chris Bolson
Chris Bolsonβ€’6mo ago
For position: fixed it will be the top of the body. For position:sticky it will be at the top of the ancestor with a position relative or absolute defined. If they don’t have an ancestor with the position defined, it will default to the body (ie the viewport in most cases) As Lamer has suggested, if you could set up a codepen with what you have (just the relevant part) that might make it easier to see what is going on.
Chris Bolson
Chris Bolsonβ€’6mo ago
In codepen you need to put the generated HTML in the HTML tab. It won't compile React as is. That said, looking at your CSS, you have used postion: fixedon everything. That is why they are all stacking at the top. Place the generated HTML code in codepen and we can take another look to try to see what you are trying to achieve and where you might be going wrong.
Chris Bolson
Chris Bolsonβ€’6mo ago
ok, getting there. Now you need to add some content otherwise there is no scroll and therefore nothing to test. Also, what is it that you want to stay at the top?
Beyond^sight
Beyond^sightOPβ€’6mo ago
I can add some context or specific height , but still that won t really help beacuse the problem is taht browser doesn t show this problem of sections moving on Y axe when scrolling happens only in the deployed version in the actual phone you can see this happening
Chris Bolson
Chris Bolsonβ€’6mo ago
Why can't this be seen in a browser? Are you using some JavaScript to target specific devices?
Beyond^sight
Beyond^sightOPβ€’6mo ago
in the browser / pc / laptop / tablem the sections / components doesn t overlap , this happens when I open the app on the mobile / actual phone @Lamer of Sweden @Chris Bolson In the responsive mode of the browser the sections doesn t overlay , the problem exist in the actual mobile view in the phone
Chris Bolson
Chris Bolsonβ€’6mo ago
but you should still be ablt to test this on a browser by making it smaller or (preferable) by using the dev tools responsive mode. That is unless you are defining different content/styles specifically for mobile devices via some JavaScript trickery.
Beyond^sight
Beyond^sightOPβ€’6mo ago
in none of the responsive mode offered in browser the componnetes doesnt move on Y axe , i discovered this problem when I checked the app in my phone to see how it look the styles used for the the are placed in the pen above
Kevin Powell
Kevin Powellβ€’6mo ago
Can you do a screen recording on your phone to show what's happening? What OS and browser are you testing on on the phone
Beyond^sight
Beyond^sightOPβ€’6mo ago
I just fixed it this morining @Kevin , I m using chrom across all devices
Want results from more Discord servers?
Add your server