I am seeking assistance to utilize Flexbox to completely fill the height of my computer screen

Seeking assistance in utilizing Flexbox to occupy 100% of my computer screen's height, all while ensuring responsiveness:

View of my current sign-in page on Chrome (Note the whitespace):

Examining my existing frontend code:

const SignIn = () => {
  return (
    <RuxContainer className="container">
      <div slot="header" className="header-container">
        <h3 className="first-header-item">LOGO</h3>
        <RuxClock timezone="Z"></RuxClock>
        <RuxMonitoringIcon status="normal"></RuxMonitoringIcon>
      </div>
      <div className="body-container">
        <form className="rux-form">
          <h2 className="body-sign-in">SIGN IN</h2>
          <h6>Measure your success in the Space Force!</h6>
          <div className="sign-in-inputs">
            <rux-input
              id="email"
              placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c386aea2aaaf83a2b0b7b1ceda0acae">[email protected]</a>"
              label="Email"
              type="email"
              ruxblur="{handleValidation()}"
            ></rux-input>
            <rux-input id="pw" label="Password" type="password"></rux-input>
          </div>
          <div className="sign-in-helper-functions">
            <rux-checkbox class="checkbox">Remember me</rux-checkbox>
            <p className="forgot-password">Forgot Password?</p>
          </div>
          <div className="sign-in-container">
            <rux-button className="sign-in-btn" type="submit">
              Sign in
            </rux-button>
          </div>
        </form>
      </div>
      <div slot="footer" className="footer">
        <p>hi</p>
      </div>
    </RuxContainer>
  );
};

export default SignIn;

Moreover, here is my CSS code utilizing flexbox:

body {
  margin: 0;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.body-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rux-form {
  width: 30%;
  max-width: 430px;
}

.sign-in-helper-functions {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.forgot-password {
  margin: 0;
  color: white;
  text-decoration: underline;
  text-decoration-color: #1976d2;
}

.sign-in-container {
  display: flex;
  justify-content: end;
  width: 100%;
  margin-top: 20px;
}

.footer {
  background-color: #172635;
}

I have attempted adjustments to the main html and body tags, but no solution seems to suffice.

Answer №1

The concept of the RuxContainer brings forth certain complex elements that are worth exploring further. One potential solution is to either exchange it with a standard div element or utilize a div to encompass its contents:

Option 1: Transition from RuxContainer to div: (not recommended)

If you substitute the RuxContainer with a regular div, the desired result can still be achieved. It's essential for the .container to occupy the full vertical height on the viewport. Optionally, you can allocate the remaining space to the .body-container. However, I advise against this method as relying on RuxContainer may be crucial for the functionality of the package.

Javascript code:

const SignIn = () => {
   return (
   <div className="container"> # Replace 'RuxContainer' with div
      # The content remains consistent
   </div>
   );
};

CSS code:

.container{
   display: flex;
   flex-direction: column;
   min-height: 100vh;
}
.body-container{
   flex: 1; /* Allows this section to expand and occupy the remaining vertical space */
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: center; /* Vertically centers the content */
}

Option 2: Wrap the RuxContainer content with div:

You can envelop the contents of RuxContainer within a div, ensuring the div extends to fill the height of the viewport while considering the padding caused by RuxContainer. Additionally, wrapping .body-container with another div permits it to utilize the leftover vertical space and centralize its content.

JavaScript code:

const SignIn = () => {
  return (
    <RuxContainer className="container">
      <div className="extend"> # To make it occupy full height
        <div slot="header" className="header-container">
          <h3 className="first-header-item">LOGO</h3>
          <RuxClock timezone="Z"></RuxClock>
          <RuxMonitoringIcon status="normal"></RuxMonitoringIcon>
        </div>
        <div className="extend__body"> # For centering the body-container contents
          <div className="body-container">
            <form className="rux-form">
              <h2 className="body-sign-in">SIGN IN</h2>
              <h6>Measure your success in the Space Force!</h6>
              <div className="sign-in-inputs">
                <rux-input
                  id="email"
                  placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="98ddf5f9f1f4d8f9ebeceaf7b6fbf7f5">[email protected]</a>"
                  label="Email"
                  type="email"
                  ruxblur="{handleValidation()}"
                />
                <rux-input id="pw" label="Password" type="password"/> 
              </div>
              <div className="sign-in-helper-functions">
                <rux-checkbox class="checkbox">Remember me</rux-checkbox>
                <p className="forgot-password">Forgot Password?</p>
              </div>
              <div className="sign-in-container">
                <rux-button className="sign-in-btn" type="submit">
                  Sign in
                </rux-button>
              </div>
            </form>
          </div>
        </div>
        <div slot="footer" className="footer">
          <p>hi</p>
        </div>
      </div>
    </RuxContainer>
  );
};

export default SignIn;

CSS code:

.extend {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 2.1rem); /* Adjust if needed for the padding caused by RuxContainer */
}

.extend__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

Answer №2

Easily achieve a layout that fills up 100% of the computer screen's height and stays responsive. By adjusting the flex-grow value on the body-container, you can alter the ratio of the header, body, and footer within the container.

 
body {
  margin: 0;
}

html, body {
  height: 100%;
}

.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
}

.body-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  flex-grow: 1;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}

Answer №3

By transforming the .container into a flex container, you gain control over the content's height in a desirable manner. To ensure responsiveness across all screen sizes, it is essential to include min-widths with this approach.

I have integrated your code (adjusted className to class attributes) so that you can visualize the solution below in a snippet.

The only modification required is within the CSS I have implemented.

body {
  margin: 0;
}

.container {
  min-height: 100vh;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-flow: column nowrap;
}

.header-container {
  min-width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.body-container {

  min-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rux-form {
  width: 30%;
  max-width: 430px;
}

.sign-in-helper-functions {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.forgot-password {
  margin: 0;
  color: white;
  text-decoration: underline;
  text-decoration-color: #1976d2;
}

.sign-in-container {
  display: flex;
  justify-content: end;
  width: 100%;
  margin-top: 20px;
}

.footer {

  min-width: 100%;
  background-color: #172635;
}
<RuxContainer class="container">
  <div slot="header" class="header-container">
    <h3 class="first-header-item">LOGO</h3>
    <RuxClock timezone="Z"></RuxClock>
    <RuxMonitoringIcon status="normal"></RuxMonitoringIcon>
  </div>
  <div class="body-container">
    <form class="rux-form">
      <h2 class="body-sign-in">SIGN IN</h2>
      <h6>Measure your success in the Space Force!</h6>
      <div class="sign-in-inputs">
        <rux-input id="email" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="22674f434b4e62435156504d">[email protected]</a>" label="Email" type="email" ruxblur="{handleValidation()}"></rux-input>
        <rux-input id="pw" label="Password" type="password"></rux-input>
      </div>
      <div class="sign-in-helper-functions">
        <rux-checkbox class="checkbox">Remember me</rux-checkbox>
        <p class="forgot-password">Forgot Password?</p>
      </div>
      <div class="sign-in-container">
        <rux-button class="sign-in-btn" type="submit">
          Sign in
        </rux-button>
      </div>
    </form>
  </div>
  <div slot="footer" class="footer">
    <p>hi</p>
  </div>
</RuxContainer>

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 difficulty with Angular's ng-options feature in a Select element

I'm currently tackling an issue with using ng-options to iterate through an array of objects and display specific properties in a select element. Upon querying the api/admin endpoint, I receive JSON data containing details of all users holding the ad ...

The mdb navigation bar seems to constantly change its height

Having an issue with the height of my mdb navbar in my Angular app. It randomly flips to a larger size when reloading the page, but returns to normal when I open the developer console in Chrome. Two screenshots show the correct display and the incorrect i ...

Executing a function should be delayed until all necessary information is obtained from the REST Api

I want to create a chart showing data for each month over the course of 12 months. The data for each month will be retrieved from a REST API. Here is my approach: $.getJSON(link, function(data){ // store data in a variable } Repeat this process 12 t ...

Is there a way to ensure that a certain block of code in Typescript is executed only after an API call has been completed?

When making an API call, I need the code after the call to wait until the API call finishes. In my function called this.api_call, it calls the API and only returns an array returnValue once the call is complete. let returnValue = this.api_call(data); // ...

Failed verification of C-Lang in React-Hardware/Particle

Currently, I am utilizing React, React Hardware ([https://github.com/iamdustan/react-hardware/]), and Johnny-Five along with the Particle Photon. The error stack displayed below is what pops up when executing my lib/app.js file: # Fatal error in ../deps/v ...

Creating a custom function in JavaScript to interact with the `windows.external` object specifically for use

In my current project, I am facing an issue with JavaScript file compatibility across different browsers. Specifically, I have a JavaScript file that calls an external function (from a separate file) using windows.external, like this: windows.external.se ...

I'm having trouble displaying the result of my calculation in the code. Could it be because I forgot to include an output tag?

I am attempting to develop a Miles Per Gallon (MPG) calculator using Javascript. However, I'm encountering difficulties with displaying the results once the "Calculate" button is pressed. <html> <head> <title> MPG Calculator </ti ...

The UI router experiences a crash and requires a refresh after precisely six clicks

Whenever the following sequence of events occurs, my application seems to malfunction. Upon clicking on a user and assigning them a role, the page refreshes. A separate GET request retrieves a list of all users currently in the class. After selecting ex ...

Transferring information from socket.io to vue.js

I am currently facing an issue with passing socket.io data to a Vue.js element. Despite going through the Vue documentation multiple times, I have not been able to find a solution. The data is being sent to the client via socket.io and successfully logged ...

Customizing the appearance of Jquery UI Accordion Headers

Trying to integrate the JQuery UI accordion into my JQuery UI modal dialog has been causing some alignment issues. Despite following code examples found online, such as http://jsfiddle.net/eKb8J/, I suspect that the problem lies in CSS styling. My setup i ...

Selenium is having trouble scrolling to the bottom of the page

Struggling to navigate to the bottom of the webpage, it seems to only scroll once before stopping, leaving a large portion of the page unseen. I'm currently using this code snippet: _inst.driver.execute_script("window.scrollTo(0, document.body.scroll ...

Jest is unable to utilize Higher Order Components from JavaScript files, but it functions properly with Higher Order Components from TypeScript files

When I try to import an HOC from a tsx file, everything works fine. However, when I change the extension to js, Jest throws an error: Jest encountered an unexpected token. This usually indicates that you are attempting to import a file that Jest is unabl ...

Navigate to the same destination with React Router Dom while passing state as a parameter

Let's talk about a scenario with a Link setup like this: <Link to={`/samelocation/${id}`} state={{ state1: 'hello' }}> This link is nested in a sub-component within the main component situated at /samelocation/:id. To ensure that the ...

Utilizing Correlated Filters in Conjunction with Firebase Database

I am struggling with a firebase query that requires adding a where() condition based on a certain criteria. Specifically, I want the where() clause to be included only if certain values are entered, otherwise the basic query should run as usual. However, ...

ReferenceError: _jquery2.default.ajax is not a function" encountered in a React Native application

I have been attempting to use jQuery to retrieve xml data from an internal website. My expo project setup is quite basic and resembles the following: import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; imp ...

Making an asynchronous request using Ajax to verify the status of a checkbox

I have two checkboxes, and I want to make an ajax call to a jsp page when one of the checkboxes is clicked. The jsp page should display a table with data fetched from a database. The issue arises when dealing with two checkboxes: <div class="search-in ...

Unnecessary spacing found within the side navigation menu

Recently, I decided to practice my web development skills by creating a basic webpage using flexbox for the topnav and CSS Grid 12 column layout for the main content. Everything was going smoothly until I encountered some extra whitespace in the sidenav se ...

Utilize the fetch function within a React functional component

I have been experimenting with different methods to fetch data only once before rendering, but I am encountering some challenges: It is not possible to call dispatch in componentDidMount as there is a restriction that it can only be done in Functional c ...

Issue: Unable to proxy the request for /logout from localhost:3000 to http://127.0.0.1:4444

Can someone assist me with resolving this concern? I attempted to use axios to send a request to /logout, but it is not functioning properly. I also tested it in postman with the same result. On the other hand, /login is working perfectly fine. https://i. ...

What is the process for converting plain text into an image tag using the methods ".replace()" and ".html()"?

My goal is to customize this particular answer so that it can transform classic BCCode [img]{url}[/img] into an HTML image. In the code snippet provided, I have successfully implemented something similar with [b]text[/b]. However, when attempting to use [i ...