Center alignment issue with Bootstrap button icons

Is there a way to vertically center the Google icon in the bootstrap social button for Google? Currently, it is not aligned properly.

I have tried using flexbox properties to align the "G" vertically but it doesn't seem to be working. Here is the snippet of my CSS code:

body {
  background-color: #E8ECEF;
}

.centered {
    padding-top: 200px;
    text-align: center;
}

.secret-text {
  text-align: center;
  font-size: 2rem;
  color: #fff;
  background-color: #000;
}
<!-- just tried this part out also didn't change the G-->
.btn-google{
    display: flex;
   align-items: center;
   justify-content: center;
}
<div class="container mt-5">
  <h1>Login</h1>

  <div class="row">
    <div class="col-sm-8">
      <div class="card">
        <div class="card-body">

          <!-- Makes POST request to /login route -->
          <form action="/login" method="POST">
            <div class="form-group">
              <label for="email">Email</label>
              <input type="email" class="form-control" name="username">
            </div>
            <div class="form-group">
              <label for="password">Password</label>
              <input type="password" class="form-control" name="password">
            </div>
            <button type="submit" class="btn btn-dark">Login</button>
          </form>

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

    <div class="col-sm-4">
      <div class="card">
        <div class="card-body">
          <a class="btn btn-block btn-social btn-google" href="/auth/google" role="button">
            <i class="fab fa-google"></i>
            Sign In with Google
          </a>
        </div>
      </div>
    </div>

  </div>
</div>

This is the complete code for my login page, excluding headers and footers. I have also included the relevant CSS and image files for reference.

Bootstrap social CSS is being used on this page as well.

Answer №1

Implementing flexbox can work wonders for your design.

.btn-google {
  /* If your button is block-level, you can use display: flex */
  display: flex;
  align-items: center;
  justify-content: center;
}

Give it a try and inform me about the outcome!

Answer №2

 .newClass{
  vertical-align: baseline;
}

experiment with this style

Answer №3

To center align items both horizontally and vertically, you can utilize flexbox. Adjusting the position of your icon in relation to your text can be achieved using the transform property.

Below is an example code snippet.

HTML


 <div class="card">
        <div class="card-body>
          <a class="btn btn-block btn-social btn-google" href="/auth/google" role="button">
            <i class="fab fa-google"></i>
            Sign In with Google
          </a>
        </div>
      </div>
    </div>


.card{
  background-color:#DD4B39;
  color:#fff;
  width:300px;
  margin:5px auto;
}
.card a{
  color:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:20px;
}
.card a i{
  margin-right:5px;
  transform:translateY(2px)
}

Answer №4

Simply apply the text-center class to your icon element; If that doesn't produce the desired result, try adding the justify-content-center class to the parent div of col-sm-4.

Answer №5

To achieve vertical centering, apply the following CSS:

  min-height: 10em;
  display: table-cell;
  vertical-align: middle

Please test this out and let me know if it works for you :)

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

Creating distinct identifiers for table cells utilizing the map function

Is there a way to assign a unique id to each MenuItem using the map() function nested within another one? <table className={classes.table}> <thead> <tr> <td /> {sit.sit.map(sit => ( <td className={ ...

How can I integrate classes into Bootstrap popover content?

By utilizing the provided html, I am able to display a popover html button. However, the issue arises when attempting to add classes to the button, as it causes the popover button to malfunction and appear on the screen. Is there a solution that allows for ...

Align the text in the center of the button vertically

Struggling to vertically center text on a button? I understand the frustration! I've been working on this issue for a whole day with no success. My setup involves NEXT.js and TailwindCSS. <main> <div class='flex justify-center ite ...

Is there any way to determine if Bootstrap has been utilized to build my WordPress page?

I'm currently contemplating if it's worth incorporating Bootstrap into my pre-existing Wordpress site. During my research, an interesting thought crossed my mind - could the template I'm utilizing already be built with Bootstrap? Although a ...

Ways to invoke a function in HTML aside from using the (click)="function()" syntax

How can I display data from a GET request to the WordPress API as the page loads in an Ionic app using Angular? I am able to retrieve my desired post list, but only when I use a button click event to call the method in the HTML. Since this is my first att ...

Troubleshooting problem with displaying circular tag image below an image using Jquery

I'm looking to enhance my HTML DOM by adding circular tag images with dimensions of 25x25 pixels to all image tags. While my current method is functional, I've noticed that the position sometimes shifts and the tag often ends up displayed below t ...

How to remove the unwanted border from the email input field in Bootstrap when using WordPress

I have implemented the Jetpack subscription form in WordPress and customized it using Bootstrap. However, I am struggling to remove an inner border that is causing issues within the Bootstrap framework. This border persists across different browsers and pl ...

Show the date broken down into day, month, and year, as well as various combinations thereof

My goal is to display the current month, year, month-year, and day-month in my HTML page. Here is the JavaScript code I am using: var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", ...

I'm at a standstill with the onclick function, even after searching on Google I couldn't

I've been struggling to make this work and have tried everything I found on Google, but I'm still stuck. What I'm trying to achieve is loading the value of (div id="availablecredits") into (div id="beta") when clicked. Can anyone help me wit ...

Changing innerHTML with HTML generated by a PHP function? (utilizing xajax)

I have managed to successfully update the content inside a DIV using xajax when clicking a link. However, I noticed that it only works when I directly assign HTML within the function itself, not when calling it from another function. Allow me to demonstra ...

What is the most effective method for developing HTML with PHP or Jquery?

My JavaScript Object contains some important information that I need to display. I have two possible options for generating the HTML from this object. I am unsure which method is the most appropriate, or if it is simply a matter of personal preference. 1 ...

How can you compare input text to the input value attribute using jQuery?

Consider this scenario: the page displays the following input element... <input class="textInput error" id="accountMailaddress" name="user[email]" size="30" type="text" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail=" ...

The tippy.js popover seems to be getting lost amidst all the scheduled events

I recently incorporated TippyJs into my FullCalendar setup for popovers, but I'm running into layout issues that seem to be related to zIndex. The popover is getting hidden behind the event wrapper and isn't clickable. I've attached a screen ...

In HTML5, the semantic tag used for indicating the "subsequent article" is

Having trouble with certain HTML5 elements. Imagine there is a blog post on one side, and a preview of the next post on the other side. Which HTML5 element would you suggest for this setup? Some might argue <nav> makes sense, while others could mak ...

Is there a way to compel the browser or JavaScript to delete/disregard a cached file?

I've encountered an issue with my Javascript program that extracts data from a text file and displays it in a table. The problem arises when I update the text file - the changes don't reflect on the table because the browser is caching the file. ...

VSCode is indicating a CSS error, requesting an at-rule or selector

I tried to implement a piece of CSS code I found on a website, but I'm encountering an error in this particular section .pricing-table:hover{ box-shadow: 0px 0px 19px -3px rgba(0,0,0,0.36); /*issue starts from this line*/ .pricing-table__button ...

Mastering jQuery placement using CSS3 "transform: scale"

There seems to be an issue with jQuery not functioning well with CSS "transform: scale()" (however, it works fine with "transform: translate()") Please examine this straightforward example: $(document).ready(function() { $('#root').dblclic ...

Creating a basic tree structure menu on a webpage can be achieved using either PHP or HTML alone, no JavaScript

Looking to develop a basic tree menu using only PHP or HTML, without the use of any JavaScript. Constraints prevent me from including JavaScript in this project. ...

Instead of displaying a preview of the file, the file upload with jQuery will now showcase the file link in a new window

I am currently working on a Jquery file upload project and I have decided not to use any plugins. My goal is to achieve this using Pure Jquery / JavaScript. Instead of previewing the file, I want to display a link (View) once the image or PDF is uploaded. ...

Open $_POST in a new tab that has been edited for your convenience

<form method="post" target="_blank" action="battle.php" onsubmit="window.open('battle.php','','width=700,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=0,left=30,top=0');" > < ...