Tips For Making Your Bootstrap 4 Page Fit Perfectly on Mobile Screens

Currently in the process of developing . The frontpage has been created and tested using Chrome's dev console's device toolbar. Ensured that the correct viewport is set and utilized Bootstrap's column system for stacking elements.

However, encountered an issue where when viewed on actual mobile devices with a mobile user agent string, the elements and fonts appear larger than intended, causing content to overflow beyond the screen width. This resulted in an error flagged by Google search console due to horizontal scrolling being enabled.

When switching the smartphone's browser to request the desktop version of the site, the display appears as expected because it sends a desktop user agent string.

Attempted to resolve this issue by implementing a reset css by copying webkit's user agent stylesheet used in Chrome desktop, hoping to override the mobile user agent stylesheet without success.

The challenge lies in continuously testing while developing as debugging on localhost is not feasible for mobile issues. As a workaround, publishing the problematic html/css to a live domain allows for real-time testing on a smartphone, although debugging becomes more challenging without the element inspector available in Chrome desktop.

This presents a significant obstacle in identifying and resolving the issue effectively.

Seeking advice on best practices for developing/debugging/testing Bootstrap pages on actual mobile devices, and ensuring consistency between the mobile and desktop versions of the site.

Update:

Created test files accessible via smartphone and displaying container div's width on the page. Discovered that the smartphone displays at 330px wide, contrary to the assumption of native resolution at 1080px. Using the dev console's device emulator at the same width unveiled the identical issue, providing a more user-friendly debugging experience.

Answer №1

I recently discovered that mobile devices do not always render websites at their full native resolution. Despite my phone's display specification being 1080px wide, it actually displays sites at a mere 330px width.

This lack of awareness led to some confusion on my part. However, once I identified the issue, I was able to replicate it using Chrome's developer console.

It turned out that the problem stemmed from hardcoded 150px paddings. Initially inserted without considering the lower rendering size of phones, these paddings caused Bootstrap columns to be squished. To rectify this, I replaced the 150px padding with a more flexible 10% padding.

While this adjustment resolved most issues, there were still a few elements exceeding the 330px width limit. To address this, I incorporated specific media screen clauses in my CSS to scale down certain elements below 400px.

Now, the page appears properly on a physical smartphone, even at 330px wide.

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

Concentrate on a specific component within an overlay using jQuery

How can I focus on a specific area within an overlay when adding an item to the cart? I want to make the rest of the overlay darker and the targeted area more visible. See a quick mockup here: https://i.sstatic.net/UpJuc.png Here's the HTML code: & ...

Invoking a Directive within another Directive

Feel free to check out this demo on Plunkr. I've set up a basic structure: <body ng-app="myApp"> <div ng-controller="myController"> <parent-directive></parent-directive> <child-directive></child-direc ...

Manipulating content with JavaScript in Internet Explorer using the outerHTML property is a powerful

Encountering an Issue with outerHTML in IE Browser If I try the following: txt = "Update Complete!"; msg = sub.appendChild(d.createElement("p")); msg.outerHTML = txt; It works without any problem. However, if I use: txt = "1 Error:<ul><li> ...

Why are my styles not working when referenced from the .module.scss file?

Here is the code snippet from my Sublayout.module.scss file: .pl-6 { padding-left: 6rem !important; } .pr-6 { padding-right: 6rem !important; } .pl-12 { padding-left: 12rem !important; } .pr-12 { padding-right: 12rem !important; } After im ...

Extract all class elements from HTML code and save them to a text file using PHP

Is there a way to extract all span elements with the class "msgsource" from my website's HTML code and then save it as a .txt file for downloading? I tried using the following code, but it only downloads an empty text file: <?php // Grabbing conte ...

White background with a black border and transparency on an Android device

I'm trying to create a shape that has a white background with a black border. <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shap ...

Challenges in Implementing Animated Counters on Mobile Platforms

My website is experiencing a strange issue with an animated counter. The counter works fine on desktop browsers, but when viewed on mobile devices in a live setting, it seems to have trouble parsing or converting numbers above 999. This results in the init ...

What is the best way to retrieve dynamic content from a .txt file and have it displayed on multiple HTML pages as they are loaded dynamically?

I have a file named 'm_data.txt' stored on the server that contains a continuous total of 77 (for instance). The total gets updated via a push.php page that writes to the .txt file. <!DOCTYPE html> <html> <head> <title> ...

The MUI component with hideBackDrop={true} is preventing me from clicking outside of the Drawer component to close it

I implemented a Drawer component which opens when an icon on the Map is clicked. The drawer menu appears along with a backshadow that drops over the map. Interestingly, clicking on the map while the backshadow is displayed closes the drawer without any i ...

When I expand the accordion next to it, the accordion disappears, and it also vanishes when I close that accordion

After incorporating accordions into my site, I encountered a peculiar issue (as shown in this video): when I open one accordion, the adjacent accordion also opens unexpectedly. Similarly, closing one accordion causes its neighboring accordion to mysterious ...

Conceal column exclusively on smaller displays using Bootstrap 4

I want to design a grid that covers the whole screen with 3 columns (left, middle, right) Left: This column should only be displayed on large views and occupy 16.6% of the screen (2/12) Middle: This column should always be visible. It should take up 75% ...

Tips for adding a new column to a website

My goal is to inject some custom HTML and CSS into YouTube in order to create a column on the right side that shifts all content towards the left. Essentially, I am trying to replicate the functionality of the Inspect Tool in Chrome. I am working on a Chr ...

the spillage exhibits only a thin streak of gray

My website is primarily a Single Page Website, however, there are specific pages that can only be accessed by registered users. On the website, there is a section referred to as a "block" where you will find a button labeled "Login / Register". Upon clicki ...

What is the best way to show the page before loading custom fonts?

My website is time-sensitive and I need it to prioritize displaying the page before loading any custom fonts. Essentially, I want the page to show up initially as if the fonts are not loaded. This way, the custom fonts (if already cached by the browser) w ...

Tips for utilizing the <base> element in HTML5 for selective anchor tags

I only have one base tag in the head section of my HTML document, and there are two anchor tags with different URLs as shown below: <!DOCTYPE html> <html lang="en"> <head> <base href="https://www.youtube.com"/> </head> &l ...

Images with scratches visible in Chrome

This puzzle may seem easy to some, but it's been quite challenging for me. I've encountered a discrepancy in how Firefox and Chrome render images (specifically technical drawings). Despite my attempts to use image-rendering: -webkit-optimize-cont ...

Attempting to verify the HTML output, yet it remains unspecified

After developing a basic testing framework, I have set myself the challenge of creating a single-page web application using vanilla JavaScript. I've been facing difficulties in figuring out why my view test is not recognizing the 'list' con ...

What is the best way to ensure that all inner divs occupy the full height of their parent div?

I am seeking a solution to make all child divs fill the full height of the parent div without specifying a fixed height. Ideally, I would like them to adjust to the height of the tallest child div. However, if the only way to achieve this is through JS, I ...

a non-breaking space within a hyperlink

While working on the subnavigation of a website, I encountered an issue with the link Suite «Mont Blanc», which was pulled from the backend. The desired format for this link was:       Suite «Mont Blanc» However, t ...

Ways to position a DIV on the right side of the screen using percentage margin to adjust its distance from the edge as the browser is resized

Allow me to provide a clearer explanation here: Imagine an element placed on a webpage with a margin of 10% from the left side. When the size of the page is adjusted, the margin on the left decreases accordingly - for example, 10% from 1400px - 140px, and ...