Make HTML design responsive to any screen size

After completing the design of a mobile app interface with dimensions 750w by 1334H, I encountered an issue where it appears too large on the app testing screen.

I am seeking a way to automatically adjust the design to fit all screens without compromising resolution. Below is the CSS code:

.username {
    background: #397ba5;
    border: none;
    width: 286;
    height: 82;
    color: white;
    font-size: 24;
}
.password {
    background: #397ba5;
    border: none;
    width: 283;
    height: 81;
    color: white;
    font-size: 24;
}

.memberlogin {
    background-color: #fc4988;
    border: none;
    width: 472;
    height: 85;
    color: white;
    font-size: 40;
    font: BOLD;
}
<html>
<head>
<title>Untitled-1</title>
<link rel="stylesheet" href="http://infinityfreight.net/style.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (Untitled-1.psd) -->
<table id="Table_01" width="640" height="1136" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="7">
<img src="http://infinityfreight.net/images/Untitled-1_01.gif" width="750" height="508" alt=""></td>
</tr>
<tr>
<td colspan="3" rowspan="4">
<img src="http://infinityfreight.net/images/Untitled-1_02.gif" width="324" height="264" alt=""></td>
<td colspan="3">
<input type=text class="username"></td>
<td rowspan="8">
<img src="http://infinityfreight.net/images/Untitled-1_04.gif" width="140" height="826" alt=""></td>
</tr>
...

Answer №1

To ensure your app adapts to various screen sizes, media queries are essential. An illustration of a media query is as follows:

MIN-WIDTH

@media only screen and (min-width: 330px)  {...}

In simpler terms:

"If the [device width] exceeds or matches [specified #], then execute {...}"

Hence, if the actual "device width" stands at 320px, this condition will yield false.

"If 320px surpasses or equals 330px, then do {...}"

MAX-WIDTH

@media only screen and (max-width: 330px)  {...}

This interprets as:

"If the [device width] is below or equal to [specified #], then perform {...}"

From this second case, if the "device width" reads 320px, the condition holds true:

"If 320px declines or equals 330px, then do {...}"

Alternative Approach - Employ Twitter Bootstrap

An effective method to craft responsive apps involves utilizing Twitter Bootstrap

Bootstrap inherently embodies mobile compatibility and responsiveness. It serves as an open-source framework for web design, encompassing HTML- and CSS-based templates for various elements like typography, forms, buttons, navigation along with JavaScript extensions.

You can access Twitter Bootstrap here

Additionally, make sure your code adequately specifies height and width. Review the updated code snippet provided below.

.username {
    background: #397ba5;
    border: none;
    width: 286px;
    height: 82px;
    color: white;
    font-size: 24;
}
.password {
    background: #397ba5;
    border: none;
    width: 283px;
    height: 81px;
    color: white;
    font-size: 24;
}

.memberlogin {
    background-color: #fc4988;
    border: none;
    width: 472px;
    height: 85px;
    color: white;
    font-size: 40;
    font: BOLD;
}

You may opt for percentage values as well.

width: 20%;

I see you're struggling with basic CSS concepts. Let me offer another example showcasing proper implementation of media queries. Remember, media queries don't encapsulate all your CSS; rather, they target specific rules that need adjustment based on varying screen sizes. Here's an exemplar to illustrate this concept.

In this demonstration, we alter the width of a div for screens smaller than 100px. Pay attention to the unit px denoting size, commonly used in many scenarios.

In the following instance, observe how we establish .div1, followed by a media query housing div1 with altered width.

.div1 {
  width: 300px;
  background: red;
  color: black;
}

@media only screen and (max-width: 330px)  {
 .div1 {
  width: 100px;
  background: red;
  color: black;
}  
}

Demonstration Result

Example one. Default css output, https://i.sstatic.net/9K2o9.png

Example two. With the media query at screen sizes under 100px. https://i.sstatic.net/3SAFz.png

Note the variance in div width prompted by differing screen dimensions.

Answer №2

When it comes to design, responsiveness is usually the way to go. However, if you have a specific vision in mind, consider using:

<meta name="viewport" content="width=320" />

This sets the width of the viewport to 320 pixels (device independent).

For more information, check out this article.

Answer №3

Utilize the CSS property @media. This allows you to define styles that will apply when the minimum screen width is X.

@media screen and (min-width: 480px) {
    .username {
        background: #397ba5;
        border: none;
        width: 286px;
        height: 82px;
        color: white;
        font-size: 24px;
    }
    .password {
        background: #397ba5;
        border: none;
        width: 283px;
        height: 81px;
        color: white;
        font-size: 24px;
    }    

    .memberlogin {
        background-color: #fc4988;
        border: none;
        width: 472px;
        height: 85px;
        color: white;
        font-size: 40px;
        font-weight: bold;
    }
}

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

Disabling the ng-click event in a confirmation popup button: a step-by-step guide

Is there a way to prevent ng-click event from triggering in a confirmation popup button? 1[Screen-Shot] ...

Contrasts in characteristics of CSS images versus SVG graphics

I'm curious if there are distinctions between CSS images and SVGs on your website. When referencing CSS images, I mean images constructed with div elements in HTML and then styled using CSS (such as this: https://codepen.io/andrewrock/pen/jOEZxrY). ...

The webpage failed to show the hamburger menu

I'm trying to create a hamburger menu and have written the following code: <header class="header"> <nav class="flex flex-jc-sb flex-ai-c"> <a href="/" class="header__logo"> <img src="im ...

Should WordPress files be kept separate (php, css, and js) or combined into a single file?

Currently, I am updating my WordPress website with a goal of minimizing the number of plugins used. To achieve this, I prefer writing code only for essential functionalities. In order to optimize my work with php, css, and javascript files, I have been exp ...

What is the best way to incorporate a custom margin within a grid system while ensuring it remains responsive?

I'm currently working on incorporating 4 non-bootstrap "cards" into my HTML layout, with some space between them. Here is an image depicting how it's supposed to look: The problem arises when I attempt to make the layout responsive by changing t ...

Implementing a stylish gradient background with HTML 5 progress bar tag

I am trying to customize an HTML5 progress bar tag in a unique way: The background of the bar should have a gradient with a fixed width of 100%, but I want the gradient to only be visible where the value of the bar is... progress[value]::-webkit-progres ...

Transform the initial HTML table row into a header row for every table by utilizing XSLT

My XML file contains HTML content that I need to manipulate. Previously, I used <xsl:copy-of select="customFields/customField[@name='mainContent']/html"/> to bring the content to the correct location. Now, I have a new requirement to conver ...

Using ChartsJs to visualize input data formatted in the German data format

I am relatively new to working with Charts.js, but I will need it to generate some visually appealing graphs for my website. In the background, I have a Django project running that calculates a specific set of numbers for me. Due to the language setting in ...

Send the completed form to a designated web address

Here's the form I'm working with: @using (Html.BeginForm("Search", "Home", FormMethod.Get, new { enctype = "multipart/form-data", @class = "navbar-form navbar-left form-inline", @role = "search" })) { var numberOfVi ...

Creating a grid layout with alternating patterns

I'm facing a challenge in creating an alternating grid layout using CSS, and it's proving to be more difficult than I anticipated. My goal is to design a layout with two boxes that alternate - first a box containing text, followed by a box displ ...

Difficulty with Flexbox in Internet Explorer 11 when utilizing a Bootstrap .badge element

At the moment, I am dealing with a flex-row that contains an element that grows with the available space and a badge that should be aligned to the end without growing. However, when using flex-grow: 0 in IE11, the span.badge does not even take up the width ...

Having trouble with your jQuery animation on a div?

Check out this jsFiddle example: http://jsfiddle.net/uM68j/ After clicking on one of the links in the demo, the bar is supposed to smoothly slide to the top. However, instead of animating, it immediately jumps to the top. How can I modify the code to ac ...

Creating a grid layout with a row of buttons

I'm currently working on aligning buttons within a div to achieve the desired effect shown in the image below. My goal is to have all buttons centered on the page, with the small circles placed in a separate div as they are initially invisible and it& ...

Placing the checkbox label within a fieldset for proper alignment

When creating a registration form, I decided to use the fieldset element to organize the input fields into two rows. Now, I am faced with the challenge of adding a checkbox below them. While I could simply use a div for this purpose, I prefer to incorpora ...

What is the best way to transform height in pixels to percentage in order to create a responsive design that adjusts smoothly on

Currently, I am in the process of developing a responsive grid system by using a max-width of 980px to convert my fixed PX widths to percentages. However, I am facing some challenges in updating the heights that are also set in PX to %. Could anyone provid ...

Styling a HTML div element with a header and footer, while also ensuring that the

My goal is to create a div that features a header with a unique background design. The content within the div should have a background consisting of a one-pixel repetition at y, or maybe something different? I also want a footer with its own distinctive ...

Tips on how to showcase it to cover a wide area

I'm having trouble figuring out how to display the output in a span element. Every time I try, I just get a blank result, and when I alert the txtNumber variable, I see "object html span element" in the alert message. <span id="displayQty"> num ...

Adjusting the width of a Material UI drawer: Tips and tricks

Currently, I am working on implementing the Material UI drawer and anchoring it to the top of my page. It is functioning correctly, however, I am encountering an issue where I am unable to adjust the width of the drawer. Despite trying to update the width ...

HTML5 will consistently display the video control panel

I am looking to keep the control panel of the html5 <video> element visible at all times while hiding the play/pause button. I attempted the following: <style> video::-webkit-media-controls-panel { display: flex !important; ...

The `class="d-none d-lg-block"` is a handy feature in Bootstrap for hiding elements

I am having trouble implementing the class="d-none d-lg-block". It does not seem to be working as expected. Here is the code that I have been attempting to use: Could you please review it and let me know if there are any errors? <div class=& ...