Employing percentage as the height measurement for a grid system

I'm facing a major issue with the website I designed; I can't seem to get the heights in percentage (%) to make everything equal. Instead, I resorted to using pixels (px) but it feels inadequate. Even after changing all the items to percentages, the divs collapse to the containing elements and don't utilize the given space properly. I have divided my page into two parts with multiple rows in each, and setting the row height only works in pixels, not percentages. Any suggestions or ideas? I will attach the relevant parts of the script here and the rest on JSFiddle.

HTML:

<div class="table-container">
<div class="table-block footer-push"><!-- Primary Page Layout
           –––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row header">
<div class="one columns"><input class="bbar" placeholder="search"></div>
<div class="eleven columns person"><span><a>Rajat Sharma</a><i class="fa fa-angle-down fa-fw op"></i></span> <img class="loginimg" src="logout.png"></div>
</div>
<div class="row">
<div class="twelve column">
<div class="pbox"><img alt="Paragon" class="pimg" src="paragon_sqaure.png"></div>
</div>
</div>
<div class="row">
<div class="ten columns PP"><a>Paragon Portal</a></div>
<div class="two columns PP"><input class="more-button" type="button" value="MORE..."></div>
</div>
</div>

/* Remaining HTML code */

CSS snippet related to the problem:

.table-container {
  display: table;
  height: 100%;
  width: 100%;
}

.table-block {
  display: table-row;
  height: 1px;
}

.footer-push {
  height: 50%;
}

#footer {
  /* Placeholder footer styles */
}

.cont { height: 50%;}

/* Grid Styles */

.container {
  position: relative;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box; }
.column,
.columns {
  width: 100%;
  float: left;
  box-sizing: border-box; }

/* Media queries and additional styling*/

Utilizing the Skeleton grid system with some modifications has caused this glitch. Despite trying to apply height percentages to certain elements, the desired effect isn't achieved. Can anyone provide insights on where things might be going wrong? The complete code is available on JSFiddle.

For an interactive preview, visit: Full-Screen Result

Answer №1

Consider this example: Create a div element and set its height to 30%.

HTML

<div id="container1"></div>

CSS

#container1 {
    background-color:#f00;
    width:30%;
    height:30%;
}

This approach won't yield the desired result as you will see a blank page. The issue lies in the fact that while you are styling the div, there are other elements on the page like html and body. By setting the height of the div to 30%, you are essentially instructing it to be 30% of the height of the body, which in turn is 100% of the height of the html. However, by default, the html element has no predefined height as it's based on its content – which is initially empty. Let's adjust the CSS slightly.

Updated CSS

#container1 {
    background-color:#f00;
    width:30%;
    height:30%;
}

html, body {
    height:100%;
}

Check out this fiddle for a demonstration: http://jsfiddle.net/r628n48L/1/

Answer №2

In my opinion, it's not a good idea to define the height of html and body as 100%, as this will cause the page to be the same height as the screen and result in overflow for everything within it.

If you want to make elements responsive to the screen by using percentage instead of fixed units, you can simply use vh. For example, set the height to 50vh, which is 50% of the viewport height. Give it a try!

You can go ahead and remove html, body {height: 100%} from your code.

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

Leveraging a web application to prevent cross-site scripting issues

Looking to incorporate a feed, similar to Twitter, onto a webpage using JavaScript (jQuery). The desired output is JSON data handed off by a "service". I have managed to create a web service that achieves this, to some extent. However, I am unsure if using ...

Troubleshooting issues with jQuery getJson() in an ASP.NET MVC environment

I'm trying to utilize jQuery to make a simple call to my MVC controller. I've successfully tested the server side, as the controller correctly received the ajax call and returned the requested information. However, on the client side, the data is ...

The iframe element triggers a ClientAbortException, resulting in a java.io.IOException at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:369)

Currently, I have implemented an iframe to display a PDF file, giving users the option to save or print it. However, I encounter an error message every time the user navigates away from the page: ClientAbortException: java.io.IOException // The rest o ...

ReactJS encountering network errors when attempting to submit a form

As a fresh developer focusing on ReactJS, I have created a registration form using ReactJS on the FrontEnd, NodeJS on the BackEnd, and MySQL for the database. When attempting to submit the register form, testing the Backend on Postman yields successful re ...

How to use JavaScript and regex to control the state of a disabled submit button

I have a challenge where I need to activate or deactivate a submission button in a form called btn-vote using JavaScript. The button will only be activated if one of the 10 radio buttons is selected. Additionally, if the person-10 radio button is chosen, t ...

Is there a method in PHP to conceal HTML code?

Although I understand that obfuscated html/js code may seem unnecessary to some (I've read similar questions on SO), I still want to add an extra layer of protection against potential copycats of my site... My website is php-based and generates html ...

Different ways to prevent invalid entries in an input field with type datetime-local

<input type="datetime-local" step="1"> Is there a way to prevent invalid date input? For example, entering a date like "11:11:1111" in the format "mm-dd-yyyy". How can this be addressed using Moment.js? ...

When attempting to add an Object from an API to my MongoDB Atlas database using Node.js, I receive an undefined error

Utilizing a third party API, I am able to retrieve a list of pokemons. My goal is to select specific ones and add them to a favorites list by clicking the "add" button. However, when attempting to display the list of favorite pokemon, all I see are objects ...

3 Methods for Implementing a Floating Header, Main Content, and Sidebar with Responsive Design

I am following a mobile-first approach with 3 containers that need to be displayed in 3 different layouts as shown in the image below: https://i.sstatic.net/UjKNH.png The closest CSS implementation I have achieved so far is this: HTML: <header>.. ...

Express.js application experiencing technical difficulties

When attempting to create a simple Express application with the file called serv.js, I encountered an error. Here is the code snippet I used: var express = require('express'), app = express(); app.listen(3000, function() { c ...

Verify whether a particular font is installed on the system

Is there a way to use JavaScript or jQuery to check if a user has Proxima Nova font installed when using Typekit? If so, I would like to incorporate that feature and then utilize jQuery to remove the Typekit loading class in order to optimize page loading ...

Checkbox remains selected despite jQuery indicating it should not be

Currently, I am in the process of developing a basic Login-Screen for a Phonegap Application using jQuery Mobile. The functionality works smoothly, allowing users to save their login information by selecting a checkbox (I utilize localStorage for this). Ho ...

Chrome browser alignment problems

Here are the lines in my code: <TD id=“avail_1” style=“display:none;availability:hidden”>UrgentAvail</TD> <TD id=“avail1_1” style=“display:none;availability:hidden”>substitutedBy</TD> When I test the application o ...

Clicking on a row in ng2-smart-table should result in the row being

I have attempted to address the issue, but I am struggling to highlight a row on click event. <ng2-smart-table [settings]="settingsPatient" [source]="sourcePatient" (userRowSelect)="patientStudy($event)" (deleteConfirm)="onDeleteConfirm($event)">" ...

showing a pair of controls side by side

I'm trying to align two controls on the same line, but currently one control appears slightly above the other. I am using bootstrap for layout. Here is my code: <div class="form-group row"> <div class="col-md-6"> ...

relocate the image with an identical filename stored in the variable

Having trouble moving an image to a new position when clicking on its small thumbnail. I've attempted using jquery's find() function but it doesn't seem to be working... $('#slide1_controls img').click(function (event){ var sr ...

Is it acceptable to exclude curly braces when declaring a function?

My current approach to declaring functions in PHP is as follows: function theFunction($theVar) { ... } Similarly, in JavaScript, I declare functions like this: function theFunction(theVar) { ... } I'm wondering if I can skip using curly brac ...

Error: An unexpected token '<' was encountered during the React Webpack build process

My ReactJs project is using Webpack4 and @babel/core 7. However, when I attempt to build the project, I encounter the following error in the terminal: ERROR in ./src/views/Pages/Login/Login.js Module build failed (from ./node_modules/babel-loader/lib ...

Is it Unwise to Depend on Props within the useReducer Hook?

Within my App() component, I utilize props named data. This particular component relies on a useReducer hook to manage its state. The reducer function is responsible for determining when to display or hide specific data based on the state. Additionally, it ...

Transfer razor javascript calls in Blazor WebAssembly to a separate class

Scenario Description Greetings, I am currently working on a Blazor WebAssembly project that involves JavaScript interop. Initially, I had this functionality working in a .razor page. However, I now intend to encapsulate and centralize these JavaScript inv ...