Struggling to align an element in HTML when used in columns?

<div class="row">
        <div class="col-lg-3 " style="border: groove;">
            <p class="circle col-xs-1 center-block">01</p>
            <h3>trending courses</h3>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellat, consectetur?</p>
        </div>
        <div class="col-lg-1"></div>
        <div class="col-lg-3" style="border: groove;">
            <p class="circle text-center">02</p>
            <h3>books&library</h3>
            <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sit nostrum voluptates tempore, pariatur nobis
                tempora repellendus deserunt suscipit, sed ex nihil eum impedit maiores quia modi qui aut velit
                veritatis quam deleniti? Quasi dolor, asperiores ut cumque laboriosam accusamus eveniet esse. Officiis
                quidem perferendis qui.</p>
        </div>
        <div class="col-lg-1">

        </div>
        <div class="col-lg-3" style="border: groove;">
            <p class="circle">03</p>
            <h3>certified teachers</h3>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellat, consectetur?</p>
        </div>
    </div>
  1. Utilized bs-5,bootstrap.bundle.min.css for styling
  2. Here is the resulting output of the code https://i.sstatic.net/PVR4Y.png

3. Provided CSS code snippet below

.circle {
            border-radius: 50%;
            width: 60px;
            height: 60px;
            padding: 10px;
            background: purple;
            border: 3px solid #000;
            display: flex;
            
            color: #fff;
            text-align: center;
            font: 28px arial, sans-serif;
            
        }
  1. Attempted using various flex methods before adjusting margin to achieve desired layout

Please assist with troubleshooting why the current setup is not functioning correctly

Answer №1

Using <span style="font-style:italic;">text-align: center</span>
on your .circle element may not be effective since it only centers the text inside the element, not the element itself. If you wish to center the circle element, consider setting margins to auto for the element instead.

If utilizing flexbox is your preference, wrap your paragraph element with a div that has styles of display: flex and justify-content: center.

Answer №2

Check out this flexbox-only approach:

.circle {
  border-radius: 50%;
  width: 60px;
  height: 60px;
  padding: 10px;
  background: purple;
  border: 3px solid #000;
  display: flex;
  color: #fff;
  text-align: center;
  font: 28px arial, sans-serif;
}
<!-- Include Bootstrap CDN -->
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="31535e5e45424543504171041f031f02">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />

<div class="row">
  <div class="col-lg-3 " style="border: groove;">
    <!-- 👇 flexbox wrapper for circle -->
    <div class="d-flex justify-content-center">
      <p class="circle col-xs-1 center-block">01</p>
    </div>
    <h3 class="text-center">trending courses</h3>
    <p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellat, consectetur?</p>
  </div>
  <div class="col-lg-1"></div>
  <div class="col-lg-3" style="border: groove;">
    <!-- 👇 flexbox wrapper for circle -->
    <div class="d-flex justify-content-center">
      <p class="circle text-center">02</p>
    </div>
    <h3 class="text-center">books&library</h3>
    <p class="text-center">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sit nostrum voluptates tempore, pariatur nobis tempora repellendus deserunt suscipit, sed ex nihil eum impedit maiores quia modi qui aut velit veritatis quam deleniti? Quasi...
  </div>
  <div class="col-lg-1">

  </div>
  <div class="col-lg-3" style="border: groove;">
    <!-- 👇 flexbox wrapper for circle -->
    <div class="d-flex justify-content-center">
      <p class="circle">03</p>
    </div>
    <h3 class="text-center">certified teachers</h3>
    <p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellat, consectetur?</p>
  </div>
</div>

By enclosing each circle in a flexbox with justify-content: center;, all elements within the flexbox will be horizontally centered.

UPDATE: The original poster requested horizontal alignment for paragraph content as well.

Answer №3

Employ this code snippet to perfectly align all components:

<div class="col-md-6 d-flex flex-row align-items-center justify-content-center"></div>

Answer №4

Consider implementing margin:auto in your CSS or m-auto in Bootstrap

Utilizing CSS

.circle {
        margin:auto
    }

To utilize Bootstrap, assign a class name to the div element as m-auto

<p class="circle text-center m-auto">02</p>

Answer №5

Utilizing Flexbox

Create a new class named dop for the parent element and chi for the child circle

<div className="col-lg-3 dop" style={{ border: "groove" }}>
        <p className="circle text-center chi">02</p>

Styling with CSS:

.dop {
  display: flex;
  flex-direction: column;
}
.chi {
  align-self: center;
}

Give it a try!

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

Is there a way to adjust the font size of a select option?

Looking to customize the appearance of a select option dropdown list. Wondering if it's possible to change the font sizes of individual options rather than keeping them all the same? For instance, having the default: -- Select Country -- displayed a ...

The combination of two tags can create a powerful and impactful presence

My task is to place two <h3> tags in the same line or paragraph. <h3>This is the first paragraph. </h3> <h3>This is the second paragraph.</h3> I would like the output to look like this: This is the first paragraph. This is Se ...

Navigate to the following div, navigate back to the previous div

I am attempting to implement a div navigation system with next/previous buttons. Despite searching extensively on Google, I have not found the exact solution I am looking for. First and foremost, I want to maintain the integrity of my html structure. < ...

"Creating multiple circles on an HTML5 canvas using an iPad: A step-by-step guide

My current code is only drawing one circle at a time on an iPad view, but I want to be able to draw multiple circles simultaneously. How can I achieve this? // Setting up touch events for drawing circles var canvas = document.getElementById('pain ...

Displaying an array of data from a list of arrays in AngularJS' session storage

Whenever a button is clicked, the data will be pushed into an array list and stored in session storage. var data = [ 'name':"name", 'id'=1 ]; var arrayList = new Array; arrayList.push(data); sess ...

Styling the navigation bar using CSS

Currently working on establishing a top menu bar similar to StackOverflow, but with a fixed position for my webpage. Check out the JSFIDDLE Demo here Encountering extra space on the left and top of the menu bar. Seeking advice on how to eliminate this ex ...

Tips for adjusting the height of a div element to completely occupy the unused portion of the viewport

How can I adjust the height of the sliding-in menu to fill the viewport below the mobile-navbar div without extending beyond it and causing scroll bars? The desired height should be: [100vh-(height of mobile-navbar)] I want to avoid setting a fixed value t ...

Creating a div that becomes fixed at the top of the page after scrolling down a certain distance is a great way to improve user experience on a

I am struggling to create a fixed navigation bar that sticks to the top of the page after scrolling 500px, but without using position: fixed. Despite trying various solutions, none seem to work due to the unique layout of my navigation bar. Strangely enoug ...

CKEditor is removing tags and attributes when formatting HTML emails

I have developed an application that enables users to import HTML emails and make adjustments before forwarding them. I am attempting to utilize CKEditor for modifying the imported email; however, it appears to be removing bgcolor tags (and possibly more). ...

Discovering the size of content through solely the height and width of a div: Is it possible?

Can someone help me figure out how to calculate the content length based solely on the height and width of a div? For example, if a Div has a height:200px & width:200px, I would like to know that the stored content length is 298. function calculateCo ...

A guide to toggling the check/uncheck status of a list box by clicking on a checkbox using

I am using a div and CSS id to control the checkbox check and uncheck functionality, but I am not getting the desired outcome from my source code Step 1: By default, the checkbox is unchecked and the listbox is disabled Step 2: When the checkbox is check ...

Preventing selection of past dates with Material UI in ReactJS

I'm currently working on a date range picker using react material ui. The goal is to allow users to select a specific date and then disable all past dates from that selected date onward. How can I go about implementing this functionality in react mate ...

Tips for interpreting Json data received from a WCF service in HTML with the help of AJAX technology?

Can anyone assist me with retrieving data details from a JSON model? I am utilizing a WCF service that returns JSON data and it works fine as I have tested it using WebClient. However, I am having trouble displaying the data on my HTML site. Despite trying ...

Is it possible to import multiple versions of a JavaScript file using HTML and JavaScript?

After extensive research, I am starting to think that using multiple versions of the same JavaScript library on a single page is not possible (without utilizing jquery Can I use multiple versions of jQuery on the same page?, which I am not). However, I wan ...

PHP library dompdf is having issues when rendering CSS styles

Trying to convert HTML with CSS styles into a PDF using dompdf. The CSS includes floats as well. Below is the snippet of my CSS and HTML code: $dompdf = new DOMPDF(); //create object //load html with css $dompdf->loadHtml('<html> <head ...

Class Div is visible only within the jQuery Tab

I have encountered a perplexing issue that has left me stumped. I recently added tabs using a jQuery plugin [Tabulous] and am in the process of transferring existing content into these tabs. However, I stumbled upon a strange problem while attempting to po ...

Creating uniform heights for HTML column-based tables using divs in a React environment

I am developing a unique column-oriented and div-based table using React with Typescript. The data outside the table is organized in a column-based structure, rendering column 1 followed by row 1, row 2, row 3, then column 2 with its respective rows. The ...

What is the best way to eliminate the underline text decoration from a link element?

Take a look at this JS Bin. I want to change the link Project name in there. By default, it is underlined when hovered over. How can I remove that effect? I attempted using a class project-name: a:hover, a:focus .project-name { text-decoration: non ...

Is the image flickering non-stop when the button is pressed?

Every time I push the button, the image on the HTML 5 canvas flickers. After investigating, it seems like the issue might be related to the ctx.clearRect(0,0,100,500) function. Any suggestions on how to fix this problem? I'm currently working on anim ...

CSS alone has the power to make multiple elements react to a hover action on a div

Is there a way to dynamically change the size of multiple div elements on hover? In this example, we can see how one div element's size changes when hovering over another div element: https://jsfiddle.net/9510a6kj/ .left, .right{ float:left; ...