Vertically align the left div in the center, while maintaining the standard alignment of the right div

I have been experimenting with Bootstrap 4 and attempting to implement the Vertical alignment feature as outlined on the webpage: https://getbootstrap.com/docs/4.0/layout/grid/

Despite reviewing my code multiple times, I am unable to identify the mistake I may be making.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="pt-md-4  row justify-content-md-center">
  <div class="col-md-5 col-lg-3">
    <div class="col align-items-center">
      <?php if($_POST){ if (isset($pin_sucess)){ ?>
      <div class="alert alert-success" role="alert">
        <h4 class="alert-heading">
          <?php echo $pin_sucess; ?>
        </h4>
      </div>
      <?php }} ?>
      <form name="timeclock" action="<?=$_SERVER['REQUEST_URI']?>" method="POST">
        <div class="form-group row">
          <label class="col-sm-2 col-form-label" for="pin">Pin</label>
          <div class="col-sm-10">
            <input type="text" name="pin" id="pin" class="form-control input-md" required="true">
          </div>
        </div>
        <div class="form-group row">
          <input type="hidden" name="csrf" value="<?php echo Token::generate();?>" />
          <div class="col-sm-2 offset-sm-2">
            <input type="submit" name="pin_submit" value="submit" class="btn btn-primary" />
          </div>
        </div>
      </form>
    </div>
  </div>
  <div class="col-md-7 col-lg-7">
    Variable width content
    <br />
    <br /> Variable width content
    <br />
    <br /> Variable width content
    <br />
    <br /> Variable width content
  </div>
</div>

The page consists of two div elements, with the left one containing the time clock form that I intend to center between the right div element.

If the content in the right div becomes too long, my goal is to convert it into a scrollable div on the right side.

For instance, if the right div extends to 2 inches in length, the left div should ideally be positioned around 1 inch lower or so.

Answer №1

To achieve the desired vertical alignment of the form div on the left with the content div on the right, simply add the col align-self-center class to the div containing the form.

Below is a working snippet demonstrating this:

.higherDiv {
  border: 1px solid black;
}

.higherDiv>.higherDiv {
  border: 1px dashed lightblue;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<div class="pt-md-4 row justify-content-md-center higherDiv">
  <!-- FORM DIV -->
  <div class="col-md-5 col-lg-3 higherDiv col align-self-center">
    <div class="col align-items-center">
      <?php if($_POST){ if (isset($pin_sucess)){ ?>
      <div class="alert alert-success" role="alert">
        <h4 class="alert-heading">
          <?php echo $pin_sucess; ?>
        </h4>
      </div>
      <?php }} ?>
      <form name="timeclock" action="<?=$_SERVER['REQUEST_URI']?>" method="POST">
        <div class="form-group row">
          <label class="col-sm-2 col-form-label" for="pin">Pin</label>
          <div class="col-sm-10">
            <input type="text" name="pin" id="pin" class="form-control input-md" required="true">
          </div>
        </div>
        <div class="form-group row">
          <input type="hidden" name="csrf" value="<?php echo Token::generate();?>" />
          <div class="col-sm-2 offset-sm-2">
            <input type="submit" name="pin_submit" value="submit" class="btn btn-primary" />
          </div>
        </div>
      </form>
    </div>
  </div>
  <!-- VARIABLE CONTENT DIV -->
  <div class="col-md-7 col-lg-7 higherDiv">
    Variable width content
    <br />
    <br /> Variable width content
    <br />
    <br /> Variable width content
    <br />
    <br /> Variable width content
    <br />
    <br /> Variable width content
    <br />
    <br /> Variable width content
  </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

transform a zipped file stream into a physical file stored on the disk

I have a Node application named MiddleOne that communicates with another Node App called BiServer. BiServer has only one route set up like this: app.get("/", (req, res) => { const file = `./zipFiles.zip`; return res.download(file); }); When Middl ...

URLs not being gathered by the web scraping tool

Currently involved in scraping data from this specific website to compile a database. Previously, I had functioning Python code available on GitHub that successfully accomplished this task. However, due to a major overhaul in the HTML structure of the site ...

Slick slider issue: Unexpected TypeError - the slick method is undefined for o[i]

I'm facing an issue where, upon clicking the search button, I want the previous search results to clear and new ones to be displayed. However, this action triggers a slick slider error, causing all items to align vertically instead of in the intended ...

Utilizing the CSS grid framework to efficiently create repetitive rows and columns in code

When I work with CSS frameworks like Bootstrap or Materialize, I often find myself repeatedly typing the same HTML code: <div class="row"> <div class="col s12"> <!-- Some text/ a button / something --> </div> </d ...

Access the child scope's attribute within the parent scope in AngularJS

angular.module('myApp',[]) .controller('Parent',['$scope',function($scope){ //no specific definition }]).controller('Child',['$scope',function($scope){ $scope.user={name:''}; //create a us ...

Breaking down an array in Node.js

After web scraping, I retrieved an array structured like this: array: [ 'line1', 'line2', 'line3', 'linen'.. ] My task now is to insert this data into a MySQL table. The challenge is that every 10 lines of ...

How to pass a method from a child component to a parent component in Vue.js

Does anyone know how to pass a function from the child component to the parent component? I have a modal in the parent component with cancel and submit buttons. When either button is clicked, I want to close the child component. I tried setting "show" in t ...

What is the best way to extract the value from an anchor element?

To retrieve the value from an input tag, we can use <id>.value like this: <input type="text" #solutionInput (keyup)="0"><br> <solutionDetail [solutionName]="solutionInput.value" > </solutionDetail> Here, 'solutionInput& ...

Three.js - Troubleshooting: Imported OBJ model displaying partially transparent triangles

Currently, I am encountering an issue with an obj file that was exported from Rhino3D into obj format. In this case, half of the triangles making up a certain part of the model appear to be transparent, despite appearing fine in the 3D editor. var loader ...

The pseudo-element ::before did not function as expected in the CSS code

I attempted to utilize the ::before element in HTML directly. Below is my code: <ul class="clear toogled" style="height:188pxl"> <li tabindex="0" style="display: block;"> <label for="MAP-IA_1_1_OR_CB_1" aria-label="Filter by product"> :: ...

Switch between various height and width options using JavaScript

Is there a way to create a toggle that changes both the height and width of an element when it is clicked? <div class="flexbox-container" id="main" onclick="staybig()">Create Account</div> .flexbox-container { ...

Trouble with collapsible panels in Embedded JavaScript

I'm having trouble iterating over my database in EJS to render them as an Accordion. I encountered 2 issues during this process. The first problem is that when I expand one accordion, they all expand simultaneously. To fix this, I attempted to assign ...

Troubles with caching on Amazon S3

Just starting out in web development and I'm working on updating HTML and CSS files stored on Amazon S3. Our website's backend is hosted on Heroku, while the front-end is on Amazon S3. Whenever I make changes to a CSS file, I can immediately see ...

The URL provided for the Ajax HTTP request is not accurate

Consider the following JavaScript code: <script type="text/javascript" charset="utf-8> function goForLogin() { var xmlhttp; xmlhttp=new XMLHttpRequest(); xmlhttp.open("POST","/account/login",true); xmlhttp.s ...

The div is not being displayed as intended with ngShow

When working with AngularJS, I encountered an issue where the ng-show function was not functioning as expected within a specific div element. ng-show="false" If you want to see the code in question, you can view it here. In line 84, I included the ng-sho ...

Switch between a list of labels dynamically with checkboxes in React

I'm currently working on a React component that displays an array of cars. I want to show a list of labels with the names of all diesel cars by default, and then have a checkbox that, when clicked, toggles to show all cars. interface ICars { name ...

JavaScript Tip: Effortless method to confirm the presence of duplicate values within an array

Similar Question: Best method for identifying duplicate values in a JavaScript array If I have an extensive array containing thousands of elements, I am looking to check if there are 2 or more elements with identical values and return true. I unders ...

Ways to automatically divide lists into various div elements

Hey there! I currently have a list of categories on my page that is subject to change. I'm looking for assistance in creating a loop that will divide my lists into groups of 5 items per div. For example: foreach($categories as $cat) <label> ...

Header of table remains fixed as user scrolls through data, allowing for easy reference. The left

Above, I have utilized some code from another answer here to display a table. However, I am now contemplating the possibility of customizing it so that the first column remains fixed for horizontal scrolling. Currently, I'm employing the following as ...

Adding a border around the `<tr>` elements in a table

How can I add a border to the <tr> element (t_border), without the inner table inheriting the style from the outer one? <table> <tr> <td>A</td> </tr> <tr> <td> <ta ...