Problem encountered when attempting to insert a new division into an existing flexbox container

I'm in the process of designing a basic login page using HTML/CSS. To center the box on the screen, I opted for a flexbox layout. So far, I have successfully positioned the Username/password fields and login button just the way I want them. The only thing left to do is add a title to the page. However, whenever I try to introduce a div element to contain the title within the flexbox container, it disrupts the positioning of the other elements.

Below is the HTML code for the login page with the title div that I wish to include commented out to demonstrate the current functionality:

html {
  margin: 0px;
  height: 100%;
  width: 100%;
}

body {
  margin: 0px;
  min-height: 100%;
  width: 100%;
}

#container {
  display: flex;
  flex-flow: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 700px;
}

#loginBox {
  height: 400px;
  width: 400px;
  background-color: white;
  box-shadow: rgba(0, 0, 0, .4) 0px 3px 8px;
}

#usernameBox {
  background-color: white;
  position: relative;
  top: 35%;
  left: 10%;
  width: 80%;
  height: 10%;
  font-size: large;
  border: 1px groove black;
  border-radius: 5px;
  text-indent: 10px;
}

#passwordBox {
  background-color: white;
  position: relative;
  top: 44%;
  left: 10%;
  width: 80%;
  height: 10%;
  width: 80%;
  font-size: large;
  border: 1px groove black;
  border-radius: 5px;
  text-indent: 10px;
}

#loginButton {
  position: relative;
  left: 58%;
  top: 53%;
  text-align: center;
  width: 130px;
  height: 40px;
  border-radius: 8px;
  background-color: rgba(0, 102, 72, 1);
  color: white;
  border: .5px solid black;
  font-size: small;
}
<div id="container">
  <div id="loginBox">
    <!-- <div id="title">Log in</div> -->
    <input id="usernameBox" placeholder="Username"></input>
    <input id="passwordBox" placeholder="Password"></input>
    <button id="loginButton" type="submit">Log in</button>
  </div>
</div>

The image below depicts the appearance prior to the addition of the title div:

Upon uncommenting the html code containing the title:

My question now arises as to how could I integrate the title into the "loginBox" while preserving the existing formatting of the Username, password fields, and the login button?

Answer №1

The issue at hand stems from setting fixed dimensions for the positions of your input elements.

To resolve this, consider utilizing the flex property and incorporating margin-top to the various elements in the following manner:

#container {
  display: flex;
  flex-flow: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 700px;
}

#loginBox {
  height: 400px;
  width: 400px;
  background-color: white;
  box-shadow: rgba(0, 0, 0, .4) 0px 3px 8px;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
}

#usernameBox {
  background-color: white;
  position: relative;
  width: 80%;
  height: 10%;
  font-size: large;
  border: 1px groove black;
  border-radius: 5px;
  text-indent: 10px;
}

#passwordBox {
  background-color: white;
  position: relative;
  width: 80%;
  height: 10%;
  width: 80%;
  font-size: large;
  border: 1px groove black;
  border-radius: 5px;
  text-indent: 10px;
}

#loginButton {
  position: relative;
  text-align: center;
  width: 130px;
  height: 40px;
  border-radius: 8px;
  background-color: rgba(0, 102, 72, 
    1);
  color: white;
  border: .5px solid black;
  font-size: small;
  align-self: end;
  margin-right: 35px;
}

#loginBox > *{
  margin-top:20px;
  
}
<div id="container">
  <div id="loginBox">
    <h1>This is the Header!</h1>
    <input id="usernameBox" placeholder="Username"></input>
    <input id="passwordBox" placeholder="Password"></input>
    <button id="loginButton" type="submit">Log in</button>
  </div>
</div>

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

The nested div does not have scrolling functionality

I'm currently working on making a nested div scrollable, but I'm encountering some challenges. The problematic div in question is the one with the "items" class. <body> <div class="page-wrapper"> <div class="header">Heade ...

Having trouble with some JS and Jquery codes not functioning properly in IE until the page is refreshed a few times. Any suggestions on how to fix this issue?

My code seems to be experiencing issues in Internet Explorer where some of the JS and jQuery codes are not functioning correctly initially, but start working after refreshing the page a few times. Any thoughts on why this could be happening? Here is the ...

Issue with margins of sections when attempting to activate menu class while scrolling

My Objective: I want to create a website where the menu highlights the section that is currently being viewed as the user scrolls up and down. Progress So Far: I have successfully implemented a functioning menu that changes to "active" when the correspo ...

Using -webkit-hyphens: auto in Safari does not function properly when the width is set to auto

I have a situation with an h3 element where I am unsure of its width. As a result, the width is set to auto by default. However, I need the text inside this element to have hyphenation applied to it. This h3 element is within a flex container along with an ...

Splitting your screen in a 10/90 column ratio using React

I am looking to split my screen into a 10/90 ratio of the total screen space. // Here is what I have attempted: return ( <> <div class="row"> <div className="col-md-4" > ; <div class="le ...

Arrange the contents within a div with Bootstrap 4 for proper alignment

Just stepping into the world of front end development and my question might come off as quite basic. Currently, I am delving into ReactJS. My current challenge is related to the following code snippet: <div className="row"> <div className="c ...

Achieving left text alignment in CSS for an excerpt using the Ultimate Posts Widget on Wordpress

I've been trying to align the text in the excerpt of a widget called "To-Do List" on the left sidebar. I attempted to set the text-align property to left for the excerpt text, targeting the p tag within the .widget_ultimate_posts, .uw posts using CSS ...

The shading of the box isn't displaying the correct color in Microsoft Edge and IE 11

I have a unique pattern consisting mainly of white and grey hues. To add a touch of color, I am using the box shadow property in CSS to apply a blue filter effect. This technique successfully displays the desired result in Firefox and Chrome browsers. Howe ...

What could be the reason my foreach loop is not being run?

After creating a login form that successfully grants access upon entering the correct email and password, there seems to be an issue. A foreach loop is implemented to test all results, with the assumption of only one account existing. foreach ($result as ...

Solving the Dilemma of Ordering Table Rows by Value in JavaScript

I am currently working on a table and my goal is to display rows in an orderly manner based on the sum of their columns. Essentially, I want the rows with the highest values to be displayed first, followed by rows with second highest values, and so on. Des ...

What is the best way to move the numerical range value into a span element?

How can I implement the "update" function to retrieve the current slider value and transfer it to a Meter element with the message "Value: [current value]". The indicator color should be #ffff00 if the current value is at least 85, otherwise, it should b ...

Angular Material Rotate Ink Bar to Vertical Orientation

After wanting to change the orientation of Angular Material's Tab Component to vertical, I visited this page (Tabs) and experimented with the CSS. By making the necessary adjustments, I successfully displayed the tabs vertically using the following CS ...

Experience mind-bending timing functions in CSS animations with IE11

Despite working perfectly on Firefox, Chrome, and Edge, the animations on my website seem to have erratic timing on IE11. To see the animation as intended: However, on IE11, the animation behaves differently: I've attempted adjusting the animation- ...

Ways to dynamically apply styles to the component tag depending on the visibility of its content

Consider a scenario where you have a component with logic to toggle the visibility of its contents: @Component({ selector: 'hello', template: `<div *ngIf="visible"> <h1>Hello {{name}}!</h1></div>`, styles: [`h1 { fo ...

Unique styling implementation for element situated underneath Angular 6 router-outlet

I'm currently working on implementing router transitions in my Angular application, and I've encountered an unusual problem. The styling for the router-outlet element is being applied to the element that comes after it in the DOM hierarchy. Here ...

using JavaScript to send numerous text box values to various views

I have a dilemma with passing values between two views. In View1, there are text boxes for entering basic information. After the customer enters this data and clicks on 'add more details', I want to transfer these details to the text boxes in Vie ...

Using jQuery and AJAX to fetch the return value of a PHP class method

Starting a new project for myself has been quite the learning experience. As someone who isn't the most skilled programmer, I decided to kick things off in PHP. However, I quickly realized that executing PHP functions and class methods through HTML bu ...

Trouble with z-index | initial div out of four malfunctioning

Currently, I am attempting to practice by replicating the design shown in this image: However, I have encountered an issue that has been persisting for some time: I'm struggling to understand why this issue is occurring. An interesting observation i ...

Column that adjusts to different screen sizes

In the realm of responsive web design, what methods are suggested to achieve the specified CSS display? My main requirement is to have a maximum of three columns. The content should be divided evenly among these three columns. I prefer using SCSS and wel ...

Adding an image to an HTML page

I am working on an HTML page and need to insert an image. Here is the code I currently have: <img src="../Images/logo.jpg" alt="Logo" height="50"> I chose "../Images/logo.jpg" as the source because my logo.jpg is located two levels up from the curr ...