Align a span and link vertically at the center in Bootstrap 4

I am having trouble centering the span and text vertically (and horizontally) inside a button that contains 7 icon links within a table. I have already made the icons bigger using the "class=bigger".

<div class="container-fluid">
    <div class="container d-flex d-inline-flex align-self-center">
        <table id="main_menu" class="table">
            <tbody>
                <tr><td colspan="2"><a href='nasbrowser/index.php' class="btn btn-light btn-lg btn-block"><span class="bigger">&#x1F9EC</span> GATK analysis </a></td></tr>

                <tr><td><a href='nasbrowser/index.php' class="btn btn-light btn-lg btn-block">
                            <span class="bigger">&#x1F4BD</span> NAS browser</a></td>
                    <td><a href='nasbrowser/index.php' class="btn btn-light btn-lg btn-block"><span class="bigger">&#x1F4CA</span> Variant browser </a></td></tr>


                <tr><td><a href='nasbrowser/index.php' class="btn btn-light btn-lg btn-block" ><span class="bigger">&#x1F4D1</span> Anotator</a></td>
                    <td><a href='nasbrowser/index.php' class="btn btn-light btn-lg btn-block"><span class="bigger">&#x2702</span> Gene filterer</a></td></tr>

                <tr><td><a href='nasbrowser/index.php' class="btn btn-light btn-lg btn-block"><span class="bigger">&#x1F3AF</span> Coverage</a></td>
                    <td><a href='nasbrowser/index.php' class="btn btn-light btn-lg btn-block"><span class="bigger">&#x1F6CC</span> Bed uploader</a></td></tr>
            </tbody>
        </table>

</div>

This is the result: https://i.sstatic.net/2jovf.png

The underlined text is not vertically centered with the icon (I made green dot where I want the text).

Answer №1

The Flexbox Layout Module offers a more convenient way to create fluid and responsive layout structures without relying on float or positioning.

To implement a Flexbox Layout, the parent element must have its display property set to flex.

Any direct child element(s) of the flexible container automatically become flexible items.

.btn-block {
    width: 100%;
    display: flex;
    align-items: center; /* vertically center elements */
    justify-content: center; /* horizontally center elements */
}

.bigger {
    font-size: 25px; /* for testing purposes */
    margin-right: 10px; /* spacing between icon and text */
}

Answer №2

After implementing your code, I found everything aligned perfectly both horizontally and vertically with the span and icon.

Could it be a case where there is some margin-top or padding-top defined in relation to your links?

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

Saving Images in HTML 5 Web SQL Database

Is it possible to save images offline using HTML 5 Web SQL Database? ...

Anyone able to solve this mysterious CSS alignment problem?

I have a search bar with two image buttons on a webpage I designed using ASP.NET. When I view the page in Internet Explorer 8, Google Chrome or Opera, I noticed that the textbox and image buttons are not aligned properly. The buttons seem to be positioned ...

What is the best way to add character limits to an HTML form?

Hello there, I am currently working on creating an HTML form to generate a PDF file. However, I am facing difficulties in figuring out how to create the character placeholders for text input fields (as shown in the screenshot of a sample PDF file below). ...

What is the process for adjusting the position following the modification of a table value in React?

In my React UI, I have set up two text fields for entering values. After saving the values, they are displayed in a table below (designed with antd). When I click on a record in the table to edit it, I want the data from that record to populate the text f ...

The image for our "About Us" section is not loading

I'm facing a challenge with displaying an image in the about us section of my website. Even though the image is present in the folder, it doesn't show up on the site. I've tried various methods such as moving the picture to different locatio ...

Accordion - Conceal Previously Revealed Items

I'm currently working on finding a solution to hide all child sections that are open in my accordion when a new header is clicked. I've included a jsfiddle link to show what I have so far. Any suggestions on how to close the opened sections would ...

Is it possible to utilize retina images with CSS3's :before selector?

Can I adjust the size of an image inserted using :before? For example, if I want to use a high resolution image in the content below - how can I specify the dimensions? .buy_tickets_btn:before{ content: url(../images/buttons/pink_ticket_btn_bg.pn ...

Unable to retrieve input values from the text fields using JavaScript

In my project, I have created two PHP pages - "doc.php" and "chkval.php". The issue I am facing is that the textfield values are not being captured in the "chkval.php" page using $POST method. An error that I encountered is: Use of undefined constant re ...

Simply tap on the image to include it in the HTML5 Canvas drawing

Currently, I am in the process of drawing a circle onto my html5 canvas as shown in the code snippet below: <!DOCTYPE HTML> <html> <head> <style> body { margin: 0px; padding: 0px; } </style> </head> <body> &l ...

Error: Property '$filter' is not defined and cannot be read

Whenever a user clicks on a link, I display the json object on the UI. However, an exception is being thrown with the following message: TypeError: Cannot read property '$filter' of undefined Check out the demo here: http://plnkr.co/edit/5NOBQ3 ...

Most effective strategy for optimizing web font loading considering caching and load speeds

When it comes to embedding fonts in your web app, there are a few different methods you can use. Method A) One way is to utilize the Google Fonts CDN by inserting this code into your HTML: <link href="https://fonts.googleapis.com/css2?family=Roboto:wg ...

Navigating a collection of objects after a button is clicked

My current library project involves looping through an array of objects to display them on a grid based on input values. Here is the code snippet for my loop: const addBook = (ev) => { ev.preventDefault(); let myLibrary = []; let bookIn ...

"Uncovering the parent element with jQuery: A step-by-step guide

I need help increasing the font size of a parent element without affecting the entire body's font size. How can I achieve this? For example, with the id="vs-1", I want to increase the font size of the grandparent li text here which is "1940". $("li ...

Is it possible for an ul to be displayed beneath a white section within an li

I am working on a JQuery carousel that is displaying correctly, but I want to make a small adjustment to the content: <li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal" style="float: left; list-style: none ...

setting different iframe widths for desktop and mobile views

I am working with an iframe and facing a challenge. I want to make it full screen width on mobile devices, but only half the screen width on a normal monitor (100% and 50%, respectively). The minimum specification for the mobile device would be iPhone, alt ...

The appearance of Bootstrap-Navbar is altered when viewed on a mobile device

After creating a website that was compatible with both web and mobile devices, I encountered an issue where the navbar would not collapse on my smartphone. However, when I resized the browser window to match the size of the smartphone screen, it worked per ...

Button shifts position as an element's visibility changes from hidden to visible

Is there a way to show an element when a button is clicked without the button moving position? When the button is clicked again, the element should disappear. var element = document.getElementById("element"); function toggleVisibility() { if (element.st ...

Enhancing the appearance of standard HTML checkboxes

This HTML snippet displays a pair of checkboxes positioned side by side <div id="mr_mrs"> <ul class="mr_mrs form-no-clear"> <li id="mr" class="popular-category"> <label for="Mr" id="mr">Mr</label> ...

Utilizing Mysql as a storage solution for articles in a WordPress-like manner

Can you please assist me in figuring out how to store an article in a database while keeping the format intact for displaying on a website? I have been searching for a solution for the past 4 days without any luck. Any guidance or help would be greatly a ...

Submission of the form was cancelled, causing a loop to occur

I'm encountering an issue with submitting a file through a standard HTML form. After uploading the file, the process seems to get trapped in a continuous loop where the file keeps uploading repeatedly. The submission of the form is done using jQuery, ...