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):

https://i.sstatic.net/pJFOi.png

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

What is causing my JS/JQuery code to only function in the console of a web browser?

I am having trouble with the $(element).scroll(function(){}); function. When I put it into a js file, it does not work properly, but when I enter it directly into the console (just the scroll func), it works fine. My goal is to implement scrolling paginat ...

Incorporating pagination with a React application by leveraging an API

I recently tackled my first pagination project using react-js-pagination and successfully created a component that retrieves, displays, and functions with data from an API. However, I faced the challenge of receiving 500 pieces of data from the API and rea ...

Introducing a variety of sub-menu fonts within an elegantly designed jQuery vertical accordion menu

I am struggling to achieve different font sizes, colors, and weights for top and sub-menu level links in my simple jQuery vertical accordion. Despite changing the CSS, I can't seem to get it right. What am I missing? Is there an easy way to accomplish ...

Tips on saving every query outcome in a separate array and delivering it back to the controller upon completion

I am currently facing an issue where I receive data in a function from my controller, and inside my model function, I need to retrieve results using a query with a dynamic value of channel. The channel ID will be coming from each checkbox on my HTML view ...

Exploring the differences between selecting an element by its class and making multiple calls to select elements

I have a question about choosing multiple elements from a page. Is it better to use a selector by class, or make multiple calls using the selector by id? The number of elements I want to select, or unwanted elements that need to be checked by the selector ...

Encountering an issue with AWS Amplify in Next.js where the properties of undefined are unable to be read, specifically in relation to 'graphql

Here's a refined version of your query tailored for Stack Overflow with properly formatted code: Title: "Error Message: Cannot read properties of undefined (reading 'graphql') while using AWS Amplify in Next.js" Context: Current ...

Determine the point spread using Jquery

Trying to figure out the point spread and determine the winner of a game based on the entered scores. I've created a function to calculate the total number of points and another function to calculate the point spread and assign a winner label. However ...

What is the best way to access the next-auth session using getStaticPaths and getStaticProps in dynamic routing scenarios?

I am currently working on implementing dynamic routing in a NextJS application. I need to retrieve the token from next-auth in order to make axios requests to an API and fetch data from getReport and getReports (located in /reports.js). However, I am facin ...

Tips for adding a "return" button to a page loaded with AJAX

While working with jQuery in prototype to load pages using Ajax, I've come across a feature on big sites like Facebook and Twitter that I'd like to implement: a 'back' button that takes the user back to the previous page when clicked. S ...

Is there a way to change the URL in the address bar without refreshing the page?

Is it possible to update the URL in the address bar without reloading the page? I came across 2 potential solutions: Option 1: Check out this link It involves using window.history.replaceState. But when I tried implementing it in my angularjs projec ...

Adjusting editable property in FullCalendar during script execution

Currently, I am working with Angular JS and fullCalendar to customize the functionality of my calendar. My goal is to change the editable property of the calendar when a button is clicked. Although it seems like a straightforward task, I am facing difficul ...

Loading screen for specific content within the current WordPress theme

I am trying to display a preloader only in the 'content' div, but it ends up hiding the entire page. The structure of the site is as follows: Title Menu Content (where I want the preloader) Footer I'm having trouble figuring out where exa ...

"Alert box displaying error message is not appearing on the screen

In order to display an error message using a tooltip, I have hidden the tooltip by setting the style of a span with an id of demo to display:none. Then I use JavaScript's getElementById method to retrieve the value of the input field with an id of use ...

Align labels on top and inputs at the bottom using Bootstrap

I'm facing an issue with alignment in my form using Bootstrap 4.4. Whenever a select element is included, it disrupts the layout by breaking the alignment of labels and inputs on the same row. Is there a way to always keep the labels at the top and t ...

Embarking on the journey of nesting components within styled-components

Check out these custom components I created: <UserImg imgUrl={userPhoto}> <DropDown> <div onClick={handleAuth}>Sign Out</div> </DropDown> </UserImg> const DropDown = styled.div` letter-spacing: 0.2em; positi ...

Tips for adjusting image dimensions with url() method in css

I have successfully incorporated collapsible functionality on my page. I would like to display a down arrow image instead of the default '+' symbol on the right side of the collapsible section. To achieve this, I can use the following CSS code s ...

Flexbox keeps elements on the same line without breaking

I'm currently delving into flexbox and aiming to create a layout similar to the one shown below: https://i.sstatic.net/epnkU.png Here is the code I have come up with: .container { display: flex; gap: 26px; } .flex50 { flex: 50%; ...

What is the procedure for displaying the complete text for choices on an ionic select button?

On my page, I have included an Ionic select button. The problem is that the options display a long string, and I want them to show the full text without truncating with dot-dot-dot like this: This is how my code looks: <ion-item *ngIf="select == &apos ...

I am having trouble getting the filter functionality to work in my specific situation with AngularJS

I inserted this code snippet within my <li> tag (line 5) but it displayed as blank. | filter: {tabs.tabId: currentTab} To view a demo of my app, visit http://jsfiddle.net/8Ub6n/8/ This is the HTML code: <ul ng-repeat="friend in user"> ...

Is it possible for an Express app.get() function to identify and handle requests for specific file extensions

Is it possible for me to manage requests for any .html file type? For example, can I achieve something like this: // server.js app.get('/*.html', (req, res) => { // perform certain actions when an html file request is made }); ...