Difficulty in centering certain elements using Bootstrap

I have recently constructed an element for a webpage within the site I am developing. The item is complete, but I am struggling to center it on the page properly. While I can easily center the image, the text associated with it refuses to budge.

Here is the HTML code:

        <article class="col-sm text-center">

            <a href="https://www.google.com/">
                <img style="border-radius: 5px;" width="400" height="561" src="https://i.imgur.com/kE1WrzV.png" alt="Image" loading="lazy" />
            </a>

            <div style="margin-top: 2%;" class="container-fluid">
                <div class="row center-block">
                    <h6 class="animestyle-title"><a class="animestyle-a" href="{{ request.path }}{{obj.mNameEN}}">This is a test (Some more test)</a></h6>
                </div>

                <div class="row center-block" style="max-width:80%;">                           
                    
                    <div>    
                        <a href="/category/{{ cat.mCategoryName }}" class="animestyle-option animestyle-a">Category 1</a>
                        <i style="color: #7d7d7d;" class="stylebullets fa fa-circle"></i>
                        <a href="/category/{{ cat.mCategoryName }}" class="animestyle-option animestyle-a">Category 2</a>
                        <i style="color: #7d7d7d;" class="stylebullets fa fa-circle"></i>
                        <a href="/category/{{ cat.mCategoryName }}" class="animestyle-option animestyle-a">Category 3</a>
                        <i style="color: #7d7d7d;" class="stylebullets fa fa-circle"></i>
                        <a href="/category" class="animestyle-option animestyle-a">...</a>
                </div>

                    <div>
                        <i style="color: #7d7d7d;" class="stylebullets fa fa-circle"></i><span class="animestyle-option">12 items</span>
                    </div>
                                                                               
                </div>

            </div>

        </article>

    </div>   

And here is the CSS:

.animestyle-title {
    font-family: Montserrat !important;
    text-align: center !important;
}

.animestyle-a {
    text-decoration: none !important;
    color: #3E3E3E !important;
    transition: all .3s !important;
}

.animestyle-option {
    color: #7d7d7d !important;
}

.stylebullets {
    font-size: 4px !important;
    display: inline-block !important;
    vertical-align: middle !important;
    margin-left: 5px;
    margin-right: 5px;
}

Answer №1

When working with elements that display inline-block, it is recommended to apply text-center to the parent container.

Keep in mind that in Bootstrap 4, the center-block class has been replaced by mx-auto, which signifies margin: 0 auto; for centering display:block elements. Bootstrap 4 also introduces a d-block class for converting inline elements to block elements if needed.

Answer №2

Issue resolved by implementing the code below:

HTML:

<article class="col-sm text-center">

    <a href="https://www.google.com/">
        <img style="border-radius: 5px;" width="400" height="561" src="https://i.imgur.com/kE1WrzV.png" alt="Image" loading="lazy" />
            </a>

        <div style="margin-top: 2%;" class="container-fluid">
            <div class="row">
                <h6 class="style-anime-title"><a class="style-anime-a" href="{{ request.path }}{{obj.mNameEN}}">This is
                        a test (Some more test)</a></h6>
            </div>

            <div class="row">

                <div class="col-sm">
                    <div>
                        <a href="/category/{{ cat.mCategoryName }}" class="style-anime-option style-anime-a">Category 1</a>
                        <i style="color: #7d7d7d;" class="style-bullets fa fa-circle"></i>
                        <a href="/category/{{ cat.mCategoryName }}" class="style-anime-option style-anime-a">Category 2</a>
                        <i style="color: #7d7d7d;" class="style-bullets fa fa-circle"></i>
                        <a href="/category/{{ cat.mCategoryName }}" class="style-anime-option style-anime-a">Category 3</a>
                        <i style="color: #7d7d7d;" class="style-bullets fa fa-circle"></i>
                        <a href="/category" class="style-anime-option style-anime-a">...</a>
                    </div>

                    <div>
                        <span class="style-anime-option">12 items</span>
                    </div>
                </div>
            </div>

        </div>

</article>

CSS:

.style-anime-title {
    font-family: Montserrat !important;
    text-align: center !important;
    margin: auto !important;
}

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

What are your thoughts on CSS alignment?

Having difficulty aligning unordered lists the way I want. Below is an image of my desired layout, looking for guidance on achieving the version on the right side. I will be using between 1 and 6 unordered lists on different pages, so a universal solution ...

Enhance the visual appeal of your checkboxes in React Fluent UI by customizing the color of the checked mark and

I have a React application using Fluent UI. Currently, the <Checkbox/> component is displaying with its default colors and behavior like this: I want to customize the color of the checked mark and label (Green for checked mark and brown for label). ...

How can one manage styling choices in R Markdown while creating a PDF document?

Currently, I am utilizing R Markdown within the RStudio platform to produce documentation. When selecting the "Knit HTML" option, my output appears satisfactory. The ability to modify styling options and apply CSS Files directly is a beneficial feature. ...

Guide on integrating materialize-css npm package into webpack

I'm currently developing a client-side application with Webpack and facing challenges when trying to incorporate the materialize-css package. Using Henrik Joreteg's hjs-webpack package, I was able to include the yeticss npm package by importing i ...

How to show a picture stored in a MySQL database using PHP

I have been experimenting with displaying images uploaded to the database using a simple insert form. So far, I have managed to retrieve the image name in the "data-file". However, I am curious about how I can easily display the actual image in the same lo ...

What order should jquery files be included in?

Today I ran into an issue while trying to add datepicker() to my page. After downloading jqueryui, I added the scripts in the following order: <script type="text/javascript" src="js/jquery.js"></script> <script src="js/superfish.js">< ...

select2 with customizable multi-column layout

Looking to create a multi-column select2 with a dynamic number of columns by specifying the number of columns as a data attribute in the select tag, or utilizing another method. <select data-cols="2,6,4"> <!--note data-cols--> < ...

AngularJS uses double curly braces, also known as Mustache notation, to display

I'm currently working on a project where I need to display an unordered list populated from a JSON endpoint. Although I am able to fetch the dictionary correctly from the endpoint, I seem to be facing issues with mustache notation as it's renderi ...

The alignment of the footer navigation is off-center

I can't seem to get my footer navigation centered properly. I've tried adjusting the CSS but it's still not working as expected. .main-footer li { float: left; font-size: 0.85em; padding: 0 0.5em; margin-bottom: 0.5em; } .main-fo ...

Sending emails through a basic HTML/PHP form is incredibly time-consuming

Seeking assistance with optimizing my email form that utilizes the POST function alongside a PHP mailto() feature. The process of sending the form takes significantly longer than expected. Any suggestions or guidance would be greatly appreciated. Here&apo ...

Unable to insert image into div element

Having trouble aligning profile images next to names instead of below the text within the div. Can't seem to figure out how to fix this issue. Just to clarify, I want the images to appear alongside the text on the page (the white image next to ' ...

Is there a way to automatically scroll to the bottom of a div when it first

Looking to enhance my application with a chat feature that automatically scrolls to the bottom of the chat page to display the latest messages. Utilizing VueJs: <template> <div id="app"> <div class="comments" ...

Insert, delete, and modify rows within the table

I'm struggling with a JavaScript issue and could use some help. How can I add a new row for all columns with the same properties as the old rows, including a "remove" button for the new row? Is there a way to prevent editing cells that contain b ...

One-click URL to trigger iPhone/iPad or Android app to open automatically in browser

Is there a specific way to create a link on an HTML page that will open an app on an iPhone, iPad, or Android device if the app is installed? I have found methods for call links and launching apps via iTunes, but is there a standard format for these types ...

Achieve consistent heights for divs within table cells without the use of JavaScript

Is it possible to make two divs contained in table cells in a shared row both have the height of the taller div without using JavaScript? Take a look at this simplified example here: http://jsfiddle.net/Lem53dn7/1/ Check out the code snippet from the fidd ...

Saving information to a hidden div using jStorage

Currently, I am utilizing jStorage for storing data in local storage. When I store the data using console.log() and later retrieve it using $.jStorage.get(), I found that the values are not being assigned to the hidden div. Can someone provide guidance o ...

The left menu icons transform upon mouseover interaction

Is there a way to dynamically change the image displayed in the left menu when hovering over it, similar to the example shown below? https://i.stack.imgur.com/HzGwR.png Currently, the image does not change on hover. We would like it to transition into a ...

A step-by-step guide on how to use ajax/jquery to access an external webpage without relying on iframe

Is there a more effective way to call another page, such as http://www.google.com, and load it into my specific div without using an iframe? I attempted to do so with ajax... $.ajax({ url : 'http://www.google.com', success : function ( ...

Issue with Cascading Dropdowns in jQuery

I am currently experiencing issues with a piece of code on my website (also accessible via this link). The code consists of 2 select fields that should display different data based on the selection made. However, I have identified 2 bugs within the code. ...

Click to Rotate the Shape

I am attempting to apply a rotation effect on a shape when clicked using jQuery and CSS. My goal is to select the element with the id of x and toggle the class rotate on and off. The rotate class utilizes the CSS transform property to achieve the desired r ...