What is the best way to center 3 divs on a webpage?

I'm struggling to center align 3 divs on the page. While I've managed to align them horizontally, I can't seem to get them centered. Whenever I try, the middle one ends up getting pushed into the third div. Here's an example image of what I mean: https://i.sstatic.net/cFfUw.jpg

Below is the HTML code I'm using with Bootstrap:

<div class="container">
    <div class="row">
      <div class="col">
        <div class="card" style="width: 18rem;">
            <img src="/pfp.jpg" class="card-img-top" alt="...">
            <ul class="list-group list-group-flush">
                <li class="list-group-item">Name: </li>
                <li class="list-group-item">Age: </li>
            </ul>
            <div id="desc" class="card-body">
              <h5 class="card-title"></h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            </div>
          </div>
      </div>
      <div id="middle" class="col">
        Colegiul National "Nicolae Titulescu"
        <div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
            <div class="carousel-indicators">
              <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
              <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
              <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
            </div>
            <div class="carousel-inner">
              <div class="carousel-item active">
                <img src="/cnntcarousel1.png" class="d-block w-100" alt="...">
              </div>
              <div class="carousel-item">
                <img src="/cnntcarousel2.png" class="d-block w-100" alt="...">
              </div>
              <div class="carousel-item">
                <img src="/cnntcarousel3.png" class="d-block w-100" alt="...">
              </div>
            </div>
            <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
              <span class="carousel-control-prev-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Previous</span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
              <span class="carousel-control-next-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Next</span>
            </button>
          </div>
      </div>
      <div class="col">
        <div class="card" style="width: 18rem;">
            <img src="/pfp.jpg" class="card-img-top" alt="...">
            <ul class="list-group list-group-flush">
                <li class="list-group-item">Name: </li>
                <li class="list-group-item">Age: </li>
            </ul>
            <div id="desc" class="card-body">
              <h5 class="card-title"></h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            </div>
          </div>
      </div>
    </div>
  </div>

And here is the CSS code I'm using:

.container {
position: absolute;
top: 40%;
left: auto;
font-family: Lemon Milk;
/*background-color: rgba(255, 255, 255, .4)*/}
#middle {
text-align: center;
color: white;}

I have a background image on the page body, which is why I'm utilizing position: absolute;.

Answer №1

An effective and versatile method involves utilizing the power of flex. For further assistance, refer to this helpful resource here

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

When using v-select to search for items, the selected items mysteriously vanish from

I recently worked on a project where I encountered a similar situation to the one showcased in this CodePen. Here is the link to the specific CodePen One issue I faced was that the selected items would disappear when performing an invalid search. After i ...

Steps to activate highlighting for the initial value in a quarterly datepicker

Concerning the quarterPicker feature in the Bootstrap datePicker (SO: how-to-change-bootstrap-datepicker-month-view-to-display-quarters, jsfiddle: jsFiddle): Is there a way to highlight an initial value upon startup? I have tried setting a value in win ...

All web browsers are supported by the HTML time input type for time formatting

Hello there, I'm currently dealing with an issue in my Angular / JHipster project. The problem lies with the input Forms, specifically the one with Type="TIME". While it displays correctly on my browser as (12:24), other browsers show it differently ...

Tips on displaying the entire text when hovering over it

I'm facing an issue with a select element that retrieves options from an API. The problem is that some options are too large for the text box and get cut off, making them hard to read for users. <div class="form-group my-4"> <lab ...

What is the best way to pass a variable using the href tag in jQuery?

for (var i in result) { $('#tgt').append( "<li><a href='/UpdateStatusData/?id='"+result[i]+" >"+result[i]+"</a></li>"); } I am facing an issue where the id is appearing blank when being extracted o ...

Challenges with image overlays in Bootstrap 4

Struggling to craft a hero image with overlaid text using Bootstrap 4. Utilizing the image-overlay class in Bootstrap cards for text placement but facing issues on mobile and other aspects. Have I hit the ceiling with Bootstrap capabilities or can adjustme ...

Issue with the navbar toggler not displaying the list items

When the screen is minimized, the toggle button appears. However, clicking it does not reveal the contents of the navbar on a small screen. I have tried loading jQuery before the bootstrap JS file as suggested by many, but it still doesn't work. Can s ...

Handlebars: Access to the property "some prop" has been denied as it is not considered an "independent property" of its parent object

Model of MongoDB: const mongoose = require('mongoose'); const ProductSchema = mongoose.Schema({ _id:mongoose.Schema.Types.ObjectId, Pid:Number, Pname:String, Price: Number, Pdesc: String, Picname: String }); module.ex ...

My issue lies with the scratch on my JavaScript menu icon

Currently in the process of creating my portfolio website, but I've hit a roadblock with the icon menu - nothing happens when I click on it. I attempted different solutions such as replacing the fontawesome icon with an image, seeking help from chatg ...

Looking for consistent vertical and horizontal scrolling behavior in a React project

I am in need of assistance as I lack the necessary expertise in ReactJs to transform this design. Currently, it is written in Jquery but I would like guidance on how to recreate it in ReactJs. Specifically, I want the left div with the topic for each row t ...

Is it possible to customize the background color of the 'rows per page' selector box in Bootstrap 4 bootstrap-table?

The text is set in white on a dark grey background by default and appears just below the formatted table. Best regards, Phil Please refer to the attached image:Section of table showing rows per page selector box ...

Error message: Angular JS function is not defined

I have been diving into AngularJS with the help of video tutorials from AngularJS.org. However, when I try to run my code, an error message pops up: Error: [ng:areq] Argument 'ReviewController' is not a function Even though my code mirrors th ...

some minor layout constraints in Bootstrap

I'm facing an issue with the bootstrap grid system. I have 6 items to display - 3 across on each line for MD screens, 2 across for SM screens, and then down to 1 for XS screens. I also need space on the left and right of each item. Currently, the setu ...

How can I transform an HTML element into a textarea using CSS or JavaScript?

While browsing a webpage, I discovered a <div> element with the class .plainMail and I want to find a way to easily select all its text by simply pressing Ctrl+A. Currently using Firefox 22, I am considering converting the div.plainMail into a texta ...

Firefox is having trouble loading SVG files

For some reason, the SVG image is loading on all browsers except for Firefox. I checked the DOM but couldn't find the code. Just to clarify, I am serving the page from Tomcat 9.0.34 <kendo-grid grid-options="gridOptions"> <img src= ...

Is Joomla equipped with shortcodes akin to those found in Wordpress?

One of the great features of WordPress is the ability to use shortcodes to insert information into HTML without the need for programming knowledge in PHP or JavaScript. This simplifies tasks and increases safety. For example (this is just a hypothetical s ...

Sort slider items using Show/Hide feature in bxSlider

I am using a bxslider on my website with specific settings: $('#carousel').bxSlider({ slideWidth: 146, minSlides: 2, maxSlides: 6, speed:500, adaptiveHeight: true, moveSlides:3, infiniteLoop : false, hideContr ...

Creating a polyBezier or polyCurve with Canvas HTML: a step-by-step guide

Looking to connect several points with a curve rather than just a straight line. I attempted using the lineTo() and bezierCurveTo() methods to draw the points. Is there anyone who can assist me in solving this dilemma? Perhaps there is a different approac ...

Tips on enhancing the size of FCKEditor's text area?

I am trying to adjust the height of the FCK Text Editor, but encountering some difficulties. Below is the code snippet I am currently using: <tr> <td colspan="2" align="left" valign="middle"> <textarea name="text" id="text" > ...

Having trouble turning off a multi-select drop down option

Hello, I'm a newcomer to AngularJs and facing an issue with disabling my multiselect dropdown under a specific condition. Initially, I attempted to disable the dropdown using the following code: document.getElementById("multidropdown").disabled = tr ...