The HTML page is not responsive to the screen size of the mobile device

Check out my HTML code:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test</title>
    <style type="text/css">
        body {
            font-size: 40px;
        }

        .screen {
            font-size: 0.5em;
            margin: 0;
            background-color: red;
            position: absolute;
            width: 8em;
            height: 19em;
            left: 0;
            top: 0;
        }

        .screen .main {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div class="screen">
        <div class="main">Ut enim benefici liberalesque sumus, non ut exigamus gratiam (neque enim beneficium faeneramur sed natura propensi ad liberalitatem sumus), sic amicitiam non spe mercedis adducti sed quod omnis eius fructus in ipso amore inest, expetendam putamus.</div>
    </div>
</body>
</html>

Despite setting the viewport meta tag to scale with the device width, the content on this page is not fitting the screen properly (I noticed white borders on my Galaxy S3). I want it to fill up completely with the red background.

What steps should I take to ensure that this page fits perfectly on various screens across different devices?

I'm new to mobile development, any guidance is appreciated. Thank you!

Answer โ„–1

Aside from BenM's response, make sure to include the following CSS code in your stylesheet to eliminate default browser styles:

html, body {
     font-size: 40px;      
     margin:0; /* remove default margin */
     padding:0; /* remove default padding */
     width:100%; /* take full browser width */
     height:100%; /* take full browser height*/
}

Your complete CSS should look like this:

.screen {
    font-size: 0.5em;
    margin: 0;
    background-color: red;
    position: absolute;
    width: 100% /* BenM mentioned this in answer*/
    height: 100%; /* take full browser height */
    left: 0;
    top: 0;
}

.screen .main {
    width: 100%; /* <--now this takes full browser dimension */
    height: 100%; /* <--now this takes full browser dimension */
}

Answer โ„–2

Give this a shot

body {
margin:0;
padding:0;
}

Answer โ„–3

Adjust the width of .screen from 8em to 100%:

.screen {
    font-size: 0.5em;
    margin: 0;
    background-color: red;
    position: absolute;
    width: 100%;
    height: 19em;
    left: 0;
    top: 0;
}

If you haven't already, make sure to reset the margin and padding on the body:

body {
    font-size: 40px;
    margin: 0;
    padding: 0;
}

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

Having trouble getting the background of the <span> element to function properly

So, here is the code I have been working on: echo "<span style='float:right; text-align:right; background-image:url('" . $icon_url . "') no-repeat top right; height:86px; width:86px; display:block;'>" . $curr_temp . "<br /> ...

How do you specifically apply an Inset Border Shadow to just two sides using CSS?

Is it possible to apply the inner shadow specifically to the bottom and right sides? I've come across some hacks, but they seem to be more focused on regular border shadows. It's easier to add a drop shadow than to remove an inner shadow. -moz-b ...

Unable to create a clickable image

My approach involves using asp:Hyperlink controls to create an image that acts as a link. Here is the sample code in both aspx and C#: <asp:HyperLink ID="mainInteractiveFileLink" runat="server"> </asp:HyperLink> C# mainInteractiveFileLink ...

Basic jQuery Slideshow Counter

I'm having trouble implementing a text-based horizontal slider on my website that scrolls left and right with mouse control. I want to display the current index of each slide along with the total number of slides (e.g. 1/4) and update the index as use ...

Looking for the optimal width ranges for media queries on laptops and cell phones?

Can anyone suggest the optimal width parameters to use in my code for different screen sizes, from tablets and laptops to cellphones, in order to create a responsive design? ...

Could it be a mistake causing Echo to fail in fetching information from advanced custom fields?

When setting up in-content advertising for my blog posts on WordPress, I wanted the ads to point towards other sections of my site. Everything was working fine with the shortcode [in-content] pulling the most recent post from the 'advertising' cu ...

Troubleshooting problems with rotate3d() in Safari on iOS

There seems to be an issue in Safari iOS version with the transform: rotate3d() I am testing it out using this HTML code <span class="safari-box"></span> For instance, when I use the following code, the animation is visible /* test ...

The image will come to life with animation as the background position is adjusted using Skrollr

Trying to create a div that switches the background image every X pixels scrolled. Initially experimented with changing the background-image, including using sprites and adjusting background position, but encountered a distracting "flickering" effect. Exa ...

Using the onMessage event in React Native WebView does not seem to have any functionality

I'm having trouble with the onMessage listener in React Native's WebView. The website is sending a postMessage (window.postMessage("Post message from web");) but for some reason, the onMessage listener is not working properly. I can't figure ...

What is the reason for the absence of styles in index.html when accessing the local server?

When using node.js to open the server, I encountered an issue where the styles are not displaying. Strangely, when opening index.html directly in the browser, all the styles show up correctly. What could be causing this discrepancy? index.html <!doctyp ...

Tips for deciding on the appropriate CSS for an Angular 6 navbar component

I am currently working on an angular 6 application where users are assigned different roles that require distinct styling. Role 1 uses Stylesheet 1, while Role 2 uses Stylesheet 2. The Navbar component is a crucial part of the overall layout structure of ...

A step-by-step guide on leveraging useRef() to specifically target dynamic material-ui tabs

When attempting to upload files to a specific channel, they always end up being uploaded to the first tab or channel. I've been using useRef to try and fix this issue, but I'm not sure what exactly is missing. By "tab," I am referring to the tab ...

HTML numbered list - precise sequence

Can I customize the format of my ordered list in HTML/CSS to look like this? o. Item 1 i. Item 2 ii. Item 3 iii. Item 4 Is it feasible to create a custom format for ordered lists using HTML and CSS? ...

switching tabs on a webpage

My PHP page has a menu tab with tabs labeled as Dash and Project. The Dash tab contains a table displaying data. The scenario is that when I click on a row in the table within the Dash tab, it should navigate to the Project tab, where a simple form is disp ...

Using javascript, hide or show a div without using jquery or the display:none property

I am looking for a way to show/hide a div up and down, but I have some requirements: I cannot use jQuery: toggle(), slideToggle(), fade, animate, etc. all use display: none, and I need the div to still occupy space in the DOM (I will be processing things ...

Eliminating the 'white-space' surrounding concealed images

I am currently working on a project where I have a list of images that need to be hidden or shown based on the click event of specific <li> elements. While I have managed to achieve this functionality successfully, I am facing an issue with white spa ...

Is there a way to dynamically adjust the font size to perfectly fit the content within a div?

There is a division element containing text: <div style="white-space:nowrap;overflow:none;width:50px;"> With some text in it </div> Is there a way to adjust the font size of the text within the division so that all of the content is display ...

Utilizing JQuery AJAX and PHP for Data Encoding

My webpage is encoded in HTML with the charset ISO-8859-2. All content on the page adheres to this charset and appears correctly. However, I am facing an issue when making an Ajax call to a PHP server. When I send the character รก and receive the same valu ...

Sending a concealed input according to the chosen option

I'm attempting to send some hidden values to a Servlet via a form, but my goal is to only pass them if the user chooses a specific option. <!-- FORM ABOVE --> <input type="hidden" name="foo" id="foo" value="foo"> <input type="hidden ...

Overflow error in Rsuite table row cannot be displayed

Please see the image above Take a look at my picture. I am facing a similar issue. I am struggling to display my error tooltip over my table row. Has anyone else encountered this problem before? Any suggestions for me? I have attempted to set the overflow ...