Arranging text within a button in perfect alignment

Trying to create buttons with icons positioned on the left side, I stumbled upon a useful example online. However, no matter how much I tweak the code, I can't seem to get the text inside the buttons to align vertically. Working within Bootstrap 4 framework. Any assistance would be greatly appreciated!

Here's the original code snippet.

Below is the snippet of the code:

.btn {
  text-align: center;
  font-size: 0.7em;
  text-transform: uppercase;
  background: #42473d;
  padding: 1em 0.5em;
  color: #fff;
}

.btn-primary:before {
  font-family: 'FontAwesome';
  font-size: 2em;
  width: (18em / 14);
  float: left;
  margin: -0.5em -0.2em;
  padding: 0.3em 0.6em;
  background-color: #292c26;
  content: "\f230";
}
.btn-secondary:before {
  font-family: 'FontAwesome';
  font-size: 2em;
  width: (25em / 14);
  float: left;
  margin: -0.5em -0.2em;
  padding: 0.3em 0.6em;
  background-color: #292c26;
  content: "\f179";
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<button class="btn btn-block rounded-0">
    View Using Facebook
</button>
<button class="btn btn-block rounded-0">
    View Using Facebook
</button>

Answer №1

When examining your code using Chrome's developer tools, it appears that the padding has been correctly applied but there is an issue with the text itself. By adding a line-height property set to initial or normal, you can resolve this problem.

.btn {
    text-align: center;
    font-size: 0.7em;
    text-transform: uppercase;
    background: #42473d;
    padding: 1em 0.5em;
    color: #fff;
    line-height: initial;
}

Answer №2

I trust this will resolve the issue you are experiencing.

.btn {
  text-align: center;
  font-size: 0.7em;
  text-transform: uppercase;
  background: #42473d;
  padding: 1em 0.5em;
  color: #fff;
  position: relative;
  height: 40px;
  overflow: hidden;
}

.btn:before {
  font-family: 'FontAwesome';
  font-size: 1.5em;
  float: left;
  padding: 4px 10px;
  height: 40px;
  width: 40px;
  background-color: #292c26;
  content: "\f230";
  position: absolute;
  left: 0;
  top: 0;
  text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<button class="btn btn-block rounded-0">
    View Using Facebook
</button>
<button class="btn btn-block rounded-0">
    View Using Facebook
</button>

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

Using the <audio> tag in HTML5 on Android devices

Exploring discussions on Android's support for the <audio> tag has been enlightening. Despite attempts on a Nexus One running Android Froyo 2.2, it seems playing audio remains elusive. As indicated by www.html5test.com, while the tag is support ...

Is there an image overlapping another image?

Currently, I am working on developing a website for a Food Cart project in my class. One of the key features I want to incorporate is the ability for users to click on an image of a plate and have a different image representing the food appear on top of it ...

What is the best way to create a border that surrounds a collection of pictures?

I'm currently facing a challenge in getting a border to perfectly fit around a collection of images. The issue can be observed in this Jsfiddle I shared, where the border aligns with the top and left edges, but not with the bottom and right edges. Her ...

Guide for splitting an HTML webpage into 3 separate divs with individual scrolling feature

Currently, I'm working on creating a website with three columns that allows users to scroll down each one independently. I attempted to set the columns at 33% width, but whenever I add content, a strange gap appears at the bottom of the screen and pr ...

Is animation not functioning for SVG path within a clip path on Firefox?

Creating the HTML for a unique effect: <svg class="svg-defs2" version="1.1" xmlns="http://www.w3.org/2000/svg" height="200" width="640"> <defs> <clipPath id="clipping2"> <!--Adjusting the x-coordinate of start will expand ...

Implement a "View All" link to toggle between displaying all items and keeping one item open by default,

I am working on multiple toggles for each letter of the alphabet. To make it easier for users, I want to add a "See All" button that will open any closed toggles. Additionally, I want the toggle for the letter A (div1) to be automatically open when the pag ...

Developing a webpage linked to a multimedia library

My family has requested that I take on the task of organizing our 'family memories' by creating an access page (which I envision as a web page) that will link to our photos and videos. Each item will be 'tagged' with information such as ...

Find the ID of the clicked table row using HTML and JavaScript

Currently, I am trying to implement this code snippet: <td align="center"> <div class="dropdown"> <button onclick="DropdownShow(this)" class="btn btn-default glyphicon glyphicon-picture"></button> <div id="@TableR ...

How can I modify the color of a jQuery Mobile Select menu?

Is there a way to dynamically modify the color (background and text) of a single select menu in jQuery Mobile, without impacting other elements with the same class? I've experimented with various approaches, such as: $('#select').css({color ...

Favicon not appearing on Jekyll website

This is my first time working with Jekyll. I'm currently working on localhost and trying to set a favicon for the website. I generated the image.ico and added the code provided to my head.html file. The image appears in my _site folder, but it's ...

Verifying the Compatibility of Linear Gradient in CSS

To verify support for CSS properties such as border-radius, use the following code snippet: if(document.createElement('test').style.borderRadius===''){ //some code } But how can I check for support of linear gradients? The declaration ...

Adjust div height to match the dynamic height of an image using jQuery

I'm facing an issue with my image setup. It has a width set to 100% and a min-width of 1024px, but I can't seem to get the 'shadow' div to stay on top of it as the window size changes. The height of the shadow div also needs to match th ...

Utilizing PHP to retrieve and insert data from a database, then display the information within a div. Despite CSS being configured with different width and height settings, the div expands accordingly

I am currently utilizing PHP to input information into a database and then use that information in a simple comment system. Being new to PHP, I am unsure if there is an easier way to achieve what I am doing. However, I am facing a challenge where if the in ...

Ways to move upward from a lower position

I am trying to create a hover effect where the title and content move to the right position upon hovering. The issue I am facing is that the transition on the `Title` class is not working, and as a result, the hover effect is also not functioning properly ...

What is the best way to add an image using a textarea or HTML editor?

Every time a user inputs text into the textarea, it works fine. However, issues arise when they try to insert an image... For instance, if they input this code in the textarea (Thumbnail image linked code) <a href="http://www.ultraimg.com/image/1V6n"& ...

Incorporating specific item into a table using PHP

On my page, I have 3 select forms and an addToCart button. The select forms are populated with data from the database to display products without any issue. However, when a user clicks on the addToCart button, I need to capture the selected values from t ...

Locating the Xpath value for a web page that frequently changes

I am facing an issue while using HTMLUnit and Xpath to extract a value from a website. Although I have managed to create the xpath to retrieve the value accurately, it does not capture the dynamic web content. Instead, it keeps fetching the value that is s ...

Enhancing Websites with Vimeo Pictures and JavaScript

Having some issues with my thumbnail system. It's supposed to fetch an image from Vimeo and display it in a div. I attempted to create a loop for a nicer look, but unfortunately, it's not working as expected. Can anyone provide assistance? ...

Align component within material-ui grid

Looking to center align the same cards but not just the grid component, I need the content itself to be equally distant from the borders and each other. I've searched and tried different solutions without luck. https://i.stack.imgur.com/aZj7H.png htt ...

Using AJAX to dynamically populate tables with Bootstrap-styled buttons

Working on a basic HTML structure where I am dynamically adding NFL Teams along with their scores <table id="tablePreview" class="table table-hover table-sm"> <thead> <tr> <th>#</th> <th>Home Team</th> ...