mobile devices experiencing scroll due to absolutely positioned elements

Is there a way to have a webpage that takes up the full height and width of the client window, but restricts scrolling on mobile devices? I want to position div elements using absolute positioning with specific transformations, such as playing cards on a table with x, y, and rotation attributes. While everything works correctly on desktop, on mobile devices when an absolutely positioned element extends beyond the parent boundaries, the browser adds a scrollbar allowing users to scroll to the out-of-bounds elements. I've tried using clip-path: inset(0) on the parent to limit the rendering of these elements, but mobile pages still allow scrolling over white space beyond the application area. Are there any other methods to confine the viewport to just the body and maintain a full-page, non-scrolling experience? The use of overflow: hidden doesn't seem effective in this case due to the absolute positioning.

For reference, here's an example:

<html>
  <head>
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <div class="app">
      <div class="square"/>
    </div>
  </body>
</html>



body {
    margin: 0;
    overflow: hidden;
}

.app {
    background-color: red;
    min-height: 100vh;
    clip-path:inset(0);
}

.square {
  background-color: blue;
  width: 100px;
  height: 100px;
  position: absolute;
  transform: translate(330px, 50px) rotate(20deg);
}

https://i.sstatic.net/DKmwg.png

Answer №1

After some exploration, I came across a solution that seems to be effective: I had to include "user-scalable=0" in the content of my viewport meta tag. Previously, the viewport was zoomed out to display the entire clipped div's bounding region, which wasn't the desired outcome. By disabling user scaling, we can maintain focus on the layout viewport.

Alternatively, I could have opted for position:fixed instead of absolute positioning to tackle this issue. However, this would have complicated the alignment of the divs since their parent may not share the same origin as the viewport.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Access an HTML file in Text Edit on a Mac directly from a web browser

Is there a way to utilize Javascript or another appropriate script to open an HTML file in Text Edit on my Mac? I have created a local web page using Text Edit that has different tabs linking to other Text Edit files within the page. I am looking for a m ...

Creating a list of font sizes for each <p> tag in my HTML document

I am looking to create an array containing the font sizes of all the p tags in my HTML document. How can I specifically target only the p elements and not their parent elements? ...

jQuery.get() function is limited to specific types of webpages

I have successfully combined multiple weather APIs on my website, which can be found here. Recently, I started using the weather.gov API and it has been quite effective. However, there are certain data points that I need to extract which the weather.gov A ...

Using Symfony2 Knp-snappy library for PDF generation, the CSS styling is not being properly imported

Attempting to create a PDF from an html.twig template, but facing some issues... Although the content is correct in the PDF, the layout is missing. It appears that the CSS files are not being imported... Bootstrap from Twitter is being used to handle the ...

Issue with a "hover" effect on a specific input[type="submit"] button

I'm having trouble getting my CSS styles to apply correctly to the input field. Can anyone help me understand why this is happening? If you'd like to take a look at the code, here are the links to the .html file and the .CSS styles. The goal is ...

The replacement of className in inline SVG is not permitted (Error: 'Cannot read property 'className.replace' of undefined')

I've hit a roadblock trying to manipulate classes within an SVG document to modify the rect elements. The code works smoothly on divs in an external document, but I've tried several other solutions as well – all listed below. I'm still rel ...

An Inquiry into the Basics of CSS and jQuery

Just getting the hang of css and jQuery, I'm utilizing a CSS class named .content for various elements on my webpage like side navigation box, picture of the day box, statistics box, etc., all laid out using definition lists. Now, when I click on the ...

Achieving left text alignment in CSS for an excerpt using the Ultimate Posts Widget on Wordpress

I've been trying to align the text in the excerpt of a widget called "To-Do List" on the left sidebar. I attempted to set the text-align property to left for the excerpt text, targeting the p tag within the .widget_ultimate_posts, .uw posts using CSS ...

Incorporate real-time calculations using JavaScript (jQuery) with variables including initialization in HTML code

As a newcomer to JavaScript, I am encountering an issue that I need help with: I would like to convert the value in the number box into the answer next to it without any changes to the value. This should also include the variables NP0, NP1, and DP0 from t ...

When using the .after() method to add jQuery elements, keep in mind that they will not trigger any

Here is the snippet of code provided: <s:file name="upload" id="upload"></s:file> $('input[id^="upload"]').change(function(){ alert("aa"); $(this).after('<input type="file" name="upload_3" id="upload_3"/> ...

Finding web page links from competition rankings using pattern matching

Challenge I am currently delving into the realm of natural language processing projects. Before diving in, I intend to explore existing works on datasets, particularly those organized on a leaderboard (refer to the "Three-way Classification" section). Ho ...

Easy Steps to Align a Rotated Table Header

I am looking to rotate the header table using CSS while keeping all text together. Here is my CSS code: th.rotate { height: 100px; white-space: nowrap; } th.rotate>div { transform: rotate(-90deg); } Here is how I have applied this CSS: ...

Creating Shadows in Swift with Xib for TableView

I am currently working on: Attached is a screenshot from an iPhone: This is the code snippet in question: cell.shadowLayerView.layer.masksToBounds = false cell.shadowLayerView.layer.shadowOffset = CGSize(width: 0, height: 0) cell.shadowLayerView.layer.s ...

Foundation and equalizer do not provide an optimal user experience

I am new to using Foundation. Currently, I am utilizing Foundation 5 along with equalizer. I have a row with 2 columns - one containing text and the other containing an image. I want both columns to have the same height, so I am using data-equalizer. ...

Tips for designing a unique mosaic using flex technology

I am attempting to design a unique mosaic layout using flexbox that resembles the image provided: https://i.sstatic.net/jrHvb.jpg Each box should have a width equivalent to one-third of the parent container, except for box 4 which needs to be double the ...

Linking two div elements together with a circular connector at the termination point of the line

I am currently working on designing a set of cards that will showcase a timeline. I envision these cards to be connected by lines with circles at each end, for a visually appealing effect. At the moment, I have created the cards themselves but I am struggl ...

Establishing the default scroll position in tables using React.js

How can I set the initial scroll in ReactJS Material-UI tables? I'm working with a table that has numerous columns and I would like to have specific columns in view automatically without having to scroll, essentially establishing an initial scroll. I ...

The element 'HTMLVideoElement' does not support the property 'captureStream'

Currently, I am working on a project that involves using WebRTC in React with typescript. I came across the MDN HTMLMediaElement.captureStream() documentation which I followed. const vid: HTMLVideoElement | null = document.querySelector("video") ...

Retrieve information from a span element located within a div container

Being new to web scraping, I am encountering what may seem like a trivial issue. Below is the HTML code in question: <div class="price-container clearfix"> <span class="sale-flag-percent">-40%</span> <span class="price-box ri"> ...

Positioning close icon on Bootstrap 4 tab

I need help aligning a close icon for a BootstrapVue tab with Bootstrap 4.2 in the top right corner. Here is my code: <b-tab v-for="order in tabs" :key="order.id"> <template slot="title"> <span class="float-left">{{ order.nam ...