CSS for creating a homescreen app with a height of 100% of the

I'm currently working on creating a CSS-based app homescreen that mimics the layout of an iPhone, where you can select different apps. Essentially, I am aiming for a 3x2 grid that spans 100% of the device's page.

My main issue is that this design needs to be compatible with various devices, which means the height and width can vary depending on the device being used.

While the width seems to be functioning correctly, there are instances where the height causes scrolling on certain devices. What I really want is for the app page to occupy the entire screen without any need for scrolling.

Here is the HTML code snippet:

<div class="outer">
    <div class="row">
        <div class="iconL">
            <img src="http://coloredwebdesign.com/wp-content/uploads/2012/02/person-icon.png" />
        </div>
         <div class="iconR">
            <img src="http://coloredwebdesign.com/wp-content/uploads/2012/02/person-icon.png" />
        </div>
    </div>
    <div class="row">
         <div class="iconL">
            <img src="http://coloredwebdesign.com/wp-content/uploads/2012/02/person-icon.png" />
        </div>
         <div class="iconR">
            <img src="http://coloredwebdesign.com/wp-content/uploads/2012/02/person-icon.png" />
        </div>
    </div>
    <div class="row">
         <div class="iconL">
            <img src="http://coloredwebdesign.com/wp-content/uploads/2012/02/person-icon.png" />
        </div>
         <div class="iconR">
            <img src="http://coloredwebdesign.com/wp-content/uploads/2012/02/person-icon.png" />
        </div>
    </div>
</div>

And here is my CSS code:

.outer{
    width: 100%;
    height: 100%;
}

.row {
    width: 100%;
}

.iconL {
    float: left;
    width: 50%;
}

.iconL img {
    float: left;
    width: 100%;
}

.iconR {
    float: left;
    width: 50%;
}

.iconR img {
    float: right;
    width: 100%;
}

I have created a JSFiddle showcasing the issue: http://jsfiddle.net/QrbKh/

As you can observe, scrolling occurs within the content despite my intention for it to cover the full screen without requiring scrolling.

Answer №1

Percents can be tricky because they are always relative to the parent element. When you inspect the Developer Tools, you'll notice that .outer has a height of 0. This is because its parent element, which is the body, does not have a set height and is therefore interpreted as zero (meaning 100% of zero is still zero).

To fix this issue, simply include the following in your CSS:

html,
body {
    height:100%;
    width:100%;
}

This will make the html and body elements fill the entire page.

Next, add the following:

.row {
    height:33.3%;
}

.iconL,
.iconR,
.iconL img,
.iconR img {
    height:100%;
}

This setup should work well. However, since dividing 100 by 3 results in a remainder, also include:

body {
    overflow:hidden;
}

Another solution is to use viewport values:

.row {
    height:33.3vh;
}

Here, "vh" stands for "viewport height," meaning 33.3vh represents one-third of the viewport's height. Viewport values generally enjoy good support across browsers. You can check their compatibility here: http://caniuse.com/#search=viewport

Answer №2

If you're looking to limit the height of an image, you can use the max-height property in CSS, like shown below. Is this what you had in mind?
Check out the demo on jsFiddle

img {
    max-height: calc(100%/3); // or 33.33%
}

Answer №3

To achieve the desired outcome, consider utilizing the following CSS code:

html, body {
    height: 100%;
    padding: 0;
    margin: 0;
}
.outer{
    height: 100%;
}
.row {
    height: 33.333333333%;
    overflow: hidden;
}
.iconL {
    float:left;
    width: 50%;
    height: 100%;
    text-align: center;
    background-color: yellow;
}
.iconL img {
    height: 100%;
    vertical-align: top;
}
.iconR {
    float:left;
    width: 50%;
    height: 100%;
    text-align: center;
    background-color: beige;
}
.iconR img {
    height: 100%;
    vertical-align: top;
}

It's essential to specify height: 100% for both html and body elements as a reference value for descendant elements.

The key lies in scaling images to match the row height, set at 33.33% of the screen height.

Including vertical-align: top for images helps tidy up any whitespace below the baseline.

With only two floated elements in the row, they can be aligned either left-to-left or right-to-right.

Adding overflow: hidden to .row ensures that floats remain within their block formatting context.

View the demo at: http://jsfiddle.net/audetwebdesign/ZYL2C/

In Firefox, the layout resembles:

You have the flexibility to align the left image on the right and the right image on the left, adjusting margins accordingly for spacing control between the images in your markup.

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

Adjust the overall cost according to the quantity using jQuery or JavaScript

I'm currently working on a project that involves input fields for Product Price, Quantity Form Field, and displaying the Total price. My goal is to have the Total price automatically update based on the product price and quantity with jQuery. I am loo ...

Dropdown button split aligned with its first button

Comparing the alignment of split button dropdowns in Bootstrap 3 and Bootstrap 4, I find that Bootstrap 3 aligns them to the left of the first button, while Bootstrap 4 only aligns them according to the second button. https://i.stack.imgur.com/gAt78.png h ...

Styling all HTML buttons globally without the need for a specific class, ID, or name attribute

To style all input tags in a different way based on their type, you can use the following CSS: input[type=button] { color:#333; font: italic 80% 'arial',sans-serif; background-color:#f0f0f0; border:2px dashed; } input[type=text] { color:#0 ...

Using a video as a background in HTML

My code has an issue where I have set overflow: hidden in the CSS but the video is still not displaying below the text as intended. The relevant CSS snippets are: fullscreen-bg { top: 0; right: 0; bottom: 0; left: 0; overflow:hidden ...

Safari: Height of 100% not functioning as expected

Currently, I have a div with the class of "signup-login-forms" that is set to have a height of 40vh and span 100% of the browser width. Inside this div are two forms positioned next to each other. The goal is to have both forms fill the entire height of th ...

Div that automatically expands

Currently facing a bit of an issue. I’m attempting to expand and retract the height of #inner upon clicking, with the intention for the height of #container to increase automatically without manually setting it to ‘auto’. Unfortunately, it seems that ...

Background header image cropped

I'm struggling to display the complete information I need on an image that I want to set as my background. Could anyone assist me in determining the correct dimensions and size? Thank you in advance for your help. #hero { width: 100%; heig ...

Removing HTML elements and accounting for new lines in a text box

I am currently utilizing CodeIgniter for my personal website, which includes multiple textareas. I am looking for a solution to prevent HTML tags from being stored in the database. Is there a tool available that can strip out any unwanted tags? Additional ...

How to Implement Horizontal Sorting with jQuery Using Various HTML Elements

Here is the current setup I have: http://www.bootply.com/sfLr2AJ7EU The issue I am facing is with moving the image (id) boxes horizontally. While I have managed to make it work vertically, attempting to do so horizontally has been unsuccessful. The image ...

primary and secondary colors within the Material UI design scheme

Is there a way to apply different colors for Cards and Papers in the Material UI Theme that are compatible with both light and dark modes? In my app, I have a list of Cards placed on top of a Paper background. Currently, the default color for both the Pap ...

State in Angular stubbornly refuses to switch despite condition changes

Here is the Typescript code, followed by the HTML: public verifySelection() { let choice = false; if (typeof this.formUser.permissionsTemplateID === undefined) { choice = true; } return choice; } <div class="form-group" ...

Different ways to update the AutoComplete Style attribute

MuiInput-formControl { margin-top: 16px; Is there a way to reset the marginTop property to zero? I attempted the following method, but it was not successful. MuiFormControlLabel: { marginTop: 0, }, <Autocomplete disabl ...

Ninja Flip ComboButton

I am looking to enhance the functionality of a toggle button within a web application that was developed using the JS Dojo API. Currently, the button is utilizing dijit.form.ToggleButton, but I need it to include an additional feature for a dropdown menu w ...

Making a floating action button in Ionic

I am currently working on creating an action floating button using the Ionic framework. While I have successfully created a basic button, I am now looking to add some stylish effects and make additional buttons appear upon interaction. I understand that th ...

Function for triggering character or camera movement upon the pressing of a button

Just starting out here with web coding and I'm trying to create a function that moves my game character when a button is pressed. The idea is to change a boolean value to "true" when the button is pressed down so that the character moves. I've at ...

Using jquery to remove textbox value when checkbox is unchecked

I have a single datatable created using jQuery. The first column of the table consists of checkboxes, and the last column contains textboxes. Because these elements are generated dynamically, they end up having identical IDs and names as shown below: $ ...

Guide to making a split background color design using only CSS

Looking for some help in designing a footer for a website with a split color design featuring two overlapping triangles. Any creative ideas are welcome! Thank you! https://i.sstatic.net/stoqy.png I tried to achieve this effect using the following code: ...

What steps do I need to take in order to resolve the routing issue with angular.js in my

Working on a mobile application with angular.js and firebase.js has been both exciting and challenging. Recently, I encountered an issue where the page refused to load properly because it was trying to access a peculiar URL file://file:///Users/patutinskij ...

How to centrally align an image with HTML tags <p></p>

https://i.sstatic.net/iTBOI.jpg I need help with HTML alignment for my website How can I center align the text with the image? #main__img { text-align: center; height: 80%; width: 80%; } .main__content p { margin-top: 1rem; font-s ...

How can I implement custom color values for individual sides of the border property in tailwind-css?

I am attempting to utilize tailwind to create a triangle shape. Here is the original code I found on the Triangle Generator. To assign colors to each side of the border, I am using the border-b-color syntax with pre-defined theme colors, which works well. ...