How to stack two DIV elements on top of each other using Bootstrap styling

I am currently using bootstrap to design the index page of my website. My goal is to align two divs in the center, one on top of the other. I have a container-fluid and a row with two columns. In one of the columns, I want to align two divs in both horizontal and vertical center (see code below).

Here's an illustration of what I'm trying to achieve: desired layout

In the image, the green represents the container-fluid, the red and blue are the divs I want centered, and the orange is a login form I plan to add later.

This is the current layout structure:

<div class="container-fluid mainwrapper p-2">
<div class="row">

    <div class="col">

        <div>
           <img src="pictures/logooo.png" class="my-2" alt="uc2">
        </div>

        <div>
           <a class="rounded shadow-sm bg-white biorHv px-3">Faculté NTIC | Departement de Scolarité</a>
        </div>
    </div>
    <div class="col">

    <!-- Login form here -->

    </div>      
</div>  
</div>

An actual photo of the issue shows that I need the green logo and text with white background to be perfectly aligned in the center of the left column.

See the problem here: actual issue

And this is what I really want to achieve: desired outcome

Answer №1

To align your divs in the center, simply add the "text-center" class as shown below:

<div class="col">

    <div class="text-center">
    <img src="pictures/logooo.png" class="my-2" alt="uc2">
    </div>

    <div class="text-center">
    <a class="rounded shadow-sm bg-white biorHv px-3">Faculté NTIC | Departement de Scolarité</a>
    </div>


</div>

By following this example, your content will be aligned in the center.

Answer №2

Here are the following instructions:

HTML

<div class="text-center">
  <img src="pictures/logooo.png" class="my-2" alt="uc2">
</div>

CSS

.col {
  padding-left:50px;
}

Answer №3

For horizontal alignment, give "col-md-6" to the column along with "text-align:center;" and "margin:0 auto". Give it a try!

<div class="container-fluid mainwrapper p-2">
<div class="row">

    <div class="col-md-6" style="text-align:center;">

<div style="float: none; margin: 0 auto;">
        <div>
        <img src="pictures/logooo.png" class="my-2" alt="uc2">
        </div>

        <div>
        <a class="rounded shadow-sm bg-white biorHv px-3">Faculté NTIC | Departement de Scolarité</a>
        </div>

<div>
    </div>



    <div class="col-md-6">

    <!-- Login form here -->

    </div>


</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

Adjust the text color when you select an element

I am trying to figure out how to change the color of my "footertext" to red when I click on either the "left" or "center" containers. Then, I want it to go back to white when I click on any of the containers (left, right, center). This is my current HTML: ...

Guide to modifying CSS properties of an individual element by manipulating class names with JavaScript

I have been searching for an answer to my question without success. I have a unique challenge where I need to change the styles of an h1 element by adding a class based on which radio button is clicked. The issue I'm facing is that when I select a dif ...

Divide HTML content while keeping inner tags intact

Currently, I am developing an online store. In my code, there is a requirement to display attributes and descriptions for multiple products on a single page. The attributes are displayed in a table format, while the description can include simple text as w ...

Whenever my code is used within Google Sites, it triggers the opening of a new and empty tab

When using this code inside an HTML box in Google Sites, a problem arises. It seems to work perfectly fine in Internet Explorer and Chrome when saved to an HTML file. However, within Google Sites, it unexpectedly opens a new tab with no data. The code st ...

Utilizing thumbnails and avatars within ion-slide in Ionic 2

When using Ionic 2, the 'ion-slide' element does not render avatar and thumbnail images in the expected sizes, instead displaying them in larger sizes. Here is the code snippet: <ion-slides> <ion-slide> <ion-item ...

What is the best way to implement iscroll4 in an iPad2 using CSS?

<html> <head> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/iscroll.js"></script> <script type="text/javascript" src="js/jquery-ui.min.js"></script> ...

Can JavaScript be utilized to dynamically adjust the size of all elements on the screen to a specified percentage of their initial height and width when a certain event occurs?

I'm fairly new to the world of JavaScript, but I have a basic understanding of it. I want to optimize my personal website for mobile devices. I've already taken care of screen orientation and element positioning, everything is centered nicely and ...

What is the best way to incorporate GLSL shader code from a separate file into the main HTML document?

Exploring the world of writing shaders has been an exciting journey for me. Using THREE.js to create an OpenGL scene and experiment with GLSL shaders has been incredibly helpful. So far, I have been embedding my GLSL code within a script field in the main ...

Employing Bootstrap4 in conjunction with Rails 5

After following the official guide and checking out this post with no success, I'm in need of some help. Can anyone shed some light on this? (source on github) Here is my Gem file: ... #bootstrap gem 'bootstrap', '~> 4.0.0.alpha3.1 ...

Using Bootstrap 4 to validate credit card information with personalized error messages

How can I apply Bootstrap 4 validation to ensure that the credit card number contains only numbers, is 16 digits long, and display appropriate messages based on user input? I want to display three distinct messages: 1. When no input is provided, show "Cre ...

What is the best way to incorporate bullet points into a textarea?

How can I make a bullet point appear when pressing the 'enter' button inside a textarea? I tried using this code, but it doesn't seem to work. Any suggestions? <script> $(".todolist").focus(function() { if(document.getElementById( ...

The background color is not displaying correctly on the <div> element

body { background-color: #FFFDEC; } .header { position: fixed; top: 0; left: 0; height: 50px; width: 100%; background-color: #04A7A6; margin: 0; display: block; z-index: 10; } .headermenu { xposition: fixed; ...

The ul element is not being properly styled by the CSS pseudoclass :checked

I recently attempted to create a responsive navigation bar using a YouTube tutorial that utilizes a checkbox to display and hide the menu on smaller screens. Despite meticulously following the tutorial and testing different browsers such as Chrome, Edge, a ...

What are some strategies for customizing the appearance of child components within a parent component?

I have a scenario where I am using parent and child components. When I use the HTML in another component, I also apply my CSS. For example, in my parent component: HTML <div class="chips"> <p class="tags">Tag 1</p&g ...

Unable to properly call a JavaScript file from an HTML file

Executing this simple code with the JavaScript line placed under Script tags will trigger the desired alert message: <!DOCTYPE html> <!-- saved from url=(0014)about:internet --> <html> <body> <script type="text/javascript" > ...

The parameter type 'Event' cannot be assigned to the argument type

edit-category-component.html: <custom-form-category *ngIf="model" [model]="model" (onSaveChanges)="handleChanges($event)"></custom-form-category> <mat-loader *ngIf="!model"></mat-loader> edi ...

By utilizing Angular's @output decorator, data can be passed from child components to their parent counterparts

I have a situation where I am passing data from a child component to a parent component, and I need to automatically check if the data is empty or has a value. This code snippet is from my login.component.ts - child TypeScript file: @Output() update = ne ...

Tips for simultaneously hovering over SVG and text elementsFeel free to hover over both SVG

After importing an SVG image and creating a box containing both an icon and text, I noticed that when hovering over the box, only the color changes to yellow while the SVG remains unaffected. How can I resolve this issue so that both the text and icon chan ...

Adding custom CSS and JavaScript to the TYPO3 backend: A step-by-step guide

Is there a way to incorporate css and javascript files into the backend? I'm aiming to enhance custom created content elements with these files, making them more visually appealing for users. Platform: TYPO3 v9 Method: Composer Mode Purpose: Cu ...

Searching for the precise draggable grid line position in rulerguides.js - tips and tricks!

Currently, I am utilizing rulerguides.js in my project. I have customized it for a specific div to display rulers and grid lines. You can refer to this FIDDLE. The rulers are functioning properly, but the draggable grid lines are being calculated based on ...