In what ways can you restrict the screen width on any browser?

If you visit this sample website at ltdcoapp.uphero.com from your smartphone and slide the screen, you will notice that the content on the right side is visible. I have tried using body{overflow-x: hidden;}, but it only works on desktop browsers.

Could you provide some advice on how to prevent this issue?

Note: I am not promoting traffic to the website, but it serves as a convenient way to demonstrate the problem.

Answer №1

Make sure to specify a fixed width when using overflow:hidden in your CSS.

Edit: Avoid using relative values like percentages for width, as they can cause issues. Stick to absolute pixel values instead (e.g. 1024px):

body {
    overflow-x: hidden;
    width: 1024px;
}

Adding viewport meta-tags in the header might also be beneficial:

<meta name="viewport" content="user-scalable=no, width=1024px, initial-scale=1.0" />

Consider disabling scrolling completely as another potential solution. Check out this resource on how to disable scrolling on mobile devices: Disable scrolling in all mobile devices

Answer №2

This method effectively disables touch response, which doesn't fit my current situation.

document.body.addEventListener('touchstart', function(e){ e.preventDefault(); });

While this approach is quite useful, it unfortunately hinders both horizontal and vertical scrolling.

document.body.addEventListener('touchmove', function(e){ e.preventDefault(); });

Keep in mind that this solution only applies to desktop browsers.

body{overflow-x: hidden;}

I've experimented with the following code multiple times, but it solely prevents users from scaling the page, without addressing the issue of right-scrolling.

<meta name="viewport" content="width=device-width; initial-scale = 1.0;user-scalable=no" />

Thanks a lot, dominikus. Your input was greatly appreciated.

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

Retain the updated select values even when the back button is pressed

My form allows users to filter through different cars with ease and efficiency. When a user selects a "Make," the corresponding "Models" populate in the next dropdown seamlessly. However, an issue arises when a user performs a search and then clicks the ...

What is the best way to include numerous attributes to an element using JavaScript?

Attributes can be included within a string in the following format: let attr = ' min="0" step="5" max="100" '; or let attr = ' min="2019-12-25T19:30" '; and so on. Is there a function available ...

What could be the reason behind the disappearance of text from the previously highlighted button in my calculator's "button grid" when I change the highlighted button?

Currently, I am in the midst of creating a tip calculator with a grid consisting of various percentage buttons. My main objective is to change the font and background color when any tip button is selected. Nevertheless, an issue has surfaced - whenever I h ...

Android PDF reader plugin

Currently, I am working on developing an online PDF library application. In order to enhance the functionality, I am in search of a suitable PDF reader plugin. If anyone has any recommendations or suggestions regarding a reliable PDF reader, kindly share ...

Retrieve a specific value from a JavaScript object

Utilizing the npm package app-store-scraper, I am extracting the app IDs of 1000 apps from the App Store. My objective is to retrieve the "id" field from each JavaScript object and save it in a .csv file. How can I accomplish this task? Below is the code ...

Running a Python Selenium script

I need some help executing this script using selenium. <div class="vbseo_liked"> <a href="http://www.jamiiforums.com/member.php?u=8355" rel="nofollow">Nyaralego</a> , <a href="http://www.jamiiforums.com/member.php?u=8870" rel="nofollo ...

React hooks causing dynamic object to be erroneously converted into NaN values

My database retrieves data from a time series, indicating the milliseconds an object spends in various states within an hour. The format of the data is as follows: { id: mejfa24191@$kr, timestamp: 2023-07-25T12:51:24.000Z, // This field is dynamic ...

Having difficulty writing to the stream with the stored reference in express-session

For my current project, I have implemented a method to upload large files to the server in manageable chunks of 10MB using the blueimp jQuery-File-Upload plugin. The backend of the application, powered by Node.js, utilizes a writeStream linked to an expres ...

Creating a dynamic dropdown menu using jQuery in conjunction with PHP and MySQL database

I am working on implementing a dynamic dropdown menu in my website to include address details such as state, city, area, and postcode. The code appears to be functioning properly when testing each component individually in the live browser. However, I enco ...

Disable responsiveness for low-resolution devices

Is there a way to disable responsive design on small resolution devices? The responsive layout appears distorted when accessed on a phone. See screenshots for more details. Phone Desktop ...

The simple-ssh Node has successfully completed its operations without encountering any errors

I'm having trouble establishing a connection to an Ubuntu EC2 instance using the Node library called simple-ssh. Below is the code snippet I'm using: const SSH = require('simple-ssh') const fs = require('fs') var ssh = new ...

Put the code inside a function. I'm new to this

My goal is to encapsulate this code: if($(window).width() > 980) { $(window).on("scroll", function() { if($(window).scrollTop() > 20) { //add black background $(".x-navbar").addClass("active"); $(".x-navbar .desktop ...

Setting a fixed height for layout with scroll functionality in Twitter Bootstrap 3.2.0

I am currently working on a design layout using bootstrap 3.2.0. I have managed to create a Fixed header and footer, and I am now facing the challenge of having a full-height container with independent scrollbars. Are there any effective methods in Twitter ...

Access JSON data from PHP server and display it in a listview on an Android platform

I have successfully developed a web service and now I am looking to retrieve the JSON object in order to populate data into an Android list view. Below is my PHP code snippet: $sql_query="SELECT * FROM testtable"; $query=mysqli_query($con,$sql_query); $ro ...

How come the margin-bottom is displaying as the margin-top?

When I attempt to add margin-bottom on a div inside its parent, it seems to display as the parent's margin-top. Why is that? HTML: <div id="wrapper"> <div id="content"> <div id="box"></div> </div> </d ...

Ellipsis malfunctioning in text overflow

It is known that the display type table-cell does not work with text-overflow ellipsis. However, this is where my issue lies. I am dealing with a file input control that appears like this: <div class="ui-select form-input" style="display:inline-block; ...

Utilizing media queries and JQuery to display a variety of menus based on screen

I have created a hamburger menu specifically for smaller screens, and it is functioning properly on small screens. However, I am facing an issue where if the menu is not open before resizing the screen to a larger size, the menu does not show at all. When ...

Images appearing blank in Android webview due to CSS background loading issue

Hello everyone! I'm having an issue with loading a web url where everything is working fine except for loading background images. I came across this page: android css background-image not found But my question is slightly different. I don't wa ...

The time that was constructed is not a valid function

I am currently working on a puppeteer script that interacts with my browser extensions and navigates to a specific page. It clicks on a particular extension button and fills in an input. Unfortunately, I am encountering an issue with the following error me ...

Issue with Vuex reactivity when dealing with a list nestled inside an object

I attempted to build a scheduler app using vuex. To set up the scheduling, I utilized a state property named "scheduleController" which is structured as an object shown below. const state = { scheduleController: { 2020: { 11: { ...