Aligning text vertically to an Ionicon using Bootstrap 3

I am attempting to vertically align an ionicon icon and text next to each other inside a button using Bootstrap 3.

My goal is to have both the text and the icon centered vertically within the button.

By default, it seems that the icon and text are aligned based on their lowest points.

Here's my HTML setup:

<div class="col-xs-4 text-right">
   <a href="/signout" class="btn btn-xs btn-danger sign-out">
      <i class="ion-power ion-fw"></i>
      <span class="menu-label">Sign Out</span>
   </a>
</div>

And here's the CSS I'm using:

.main-header .navbar .dropdown-menu li a.sign-out {
   color: #fff !important;
   vertical-align: middle;
}

.ion-fw {
    width: 1.28571429em;
    text-align: center;
}

The CSS styles seem to be targeting the elements correctly as the colors display properly. I've experimented with padding and margins on .menu-label, but this ends up moving both the text and the icon.

Can anyone suggest a way to adjust the text so that it aligns with the middle of the icon's height? Thank you!

For reference, please see the example image below: https://i.sstatic.net/b5ctd.png

Answer №1

Modify this

.ion-fw {
    width: 1.28571429em;
    text-align: center;
}

to something like this

.ion-fw {
    width: 1.28571429em;
    text-align: center;
   vertical-align: middle;
}

The use of vertical-align impacts elements within the same container, requiring it to be applied to the contents rather than the parent element.

.ion-fw {
  width: 1.28571429em;
  text-align: center;
  vertical-align: middle;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-4 text-right">
  <a href="/signout" class="btn btn-xs btn-danger sign-out">
    <i class="ion-power ion-fw"></i>
    <span class="menu-label">Sign Out</span>
  </a>
</div>

Answer №2

I found a solution that works well for my situation:

.ion-fw {
  display: inline-block;
  vertical-align: bottom;
  height: 1.4em;
  font-size: 1.1em;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-4 text-right">
  <a href="/signout" class="btn btn-xs btn-danger sign-out">
    <i class="ion-power ion-fw"></i>
    <span class="menu-label">Sign Out</span>
  </a>
</div>

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 is the best method for submitting an ArrayList of child objects using a form?

Experimenting with form submission to observe the behavior when errors occur in certain fields. Utilizing Thymeleaf to extract object data and populate input fields within the form. Encountering an issue where, despite proper validation results (BindingR ...

Extracting updated dom elements with a query

Within my HTML document, I have a div section containing various form input elements. Using jQuery('#div').html(), I can retrieve the original content of this section. However, when I make changes to the form inputs by entering text or selecting ...

Bootbox Dialog Form

Looking to implement a functionality where a Bootbox dialog pops up with an "OK" button. Upon clicking the "OK" button, it should initiate a POST request, sending back the ID of the message to acknowledge that the user has read it. The Bootbox dialog fun ...

What is causing all font-faces (such as glyphicon icons) to load correctly only when utilizing Bootstrap's online CDN source file?

I recently encountered an issue with my Plunker code (https://embed.plnkr.co/KpVqaiblOKGk5K6VWmi4/), where everything worked perfectly in Microsoft Visual Studio Code. However, when I tried to use the Bootstrap source file offline by setting the link' ...

Bootstrap's pill-tab feature isn't functioning properly

Why is this tab not functioning properly? Do I need to make changes to the jQuery section? The Id and Href appear to be correct, but the tab is not working as expected. $('#v-pills-tab a').on('click', function (e) { e.pr ...

Centralized and standardized approach to invoking a function

Explaining this concept may be a bit challenging, but I'll give it a shot: Within the .boxes class div, there are looped elements with the class .box. Each .box element contains two child elements: one with the class .box-header and another with the ...

Creating a dynamic HTML table using Vue 3

My table is not showing the data I'm fetching from my API. Even though I can see the data in my console.log, it's not populating the table. Could there be an issue with how I'm calling the data to display in the table? <template> < ...

Achieving a centrally aligned flex container with left-aligned flex items

My goal is to center the flex items, but when they go onto a second line, I want item 5 (from image below) to be positioned under item 1 instead of centered in the parent container. https://i.sstatic.net/GhD1E.png Here's a sample of my current setup ...

Optimal method for relocating an element efficiently

I'm currently working on a project where I need to implement horizontal movement for a DOM element. The movement should start on mousedown, continue on mousemove, and end on mouseup. This task is especially challenging due to the site's numerous ...

Having trouble retrieving data from a remote URL with angucomplete-alt

Utilizing the angucomplete-alt directive for creating an autocomplete list through a get request. Successfully fetching results from the Github API: <div angucomplete-alt id="ex5" placeholder="Search projects" pause="500" selected-object="selectedProj ...

How can I use a dropdown list to filter data in PHP and SQL?

We are in the process of implementing a filter feature based on tags or a dropdown menu for our blog website. This will allow users to filter the content posted on the homepage by selecting specific tags. Click here for the Tags dropdown menu. The page s ...

How can I choose the first n children up to a certain class using CSS?

Take a look at this HTML : <div class="container"> <a id="1"></a> <a id="2"></a> <a id="3"></a> <a id="4"></a> <a id="5" class="specific"></a> <a id="6"></a ...

What is the best approach to execute a javascript on an HTML page that is dynamically generated?

Working with jQuery Mobile, I have a situation where I am creating a listView of pages based on events stored in a database. Each event is parsed on my webpage to generate a unique HTML page for each one. Within each page, I include a distinct "subscribe" ...

I incorporated a CSS file from another HTML document. What do you think about that?

In my work with Ionic 3 and angular 4, each HTML file is accompanied by its own CSS file. There are times when I reference a class in one HTML file that is defined in another HTML file. I have observed that this CSS class gets injected into the main.js He ...

Alternative Email for Outlook and Gmail

Hey amazing and intelligent buddies! I've been working on implementing a fallback system for email clients, but despite consulting resources like this HTML Emails: fallback for mso conditional? and other insightful blogs, I still seem to be facing so ...

Background anchor in Internet Explorer 7

Why is there an issue with the css background property for anchors in IE 7? css: .nav a { float: left; display: block; padding: 5px; height: 25px; line-height: 25px; font-weight: bold; } .nav a:hover { background: #fff; co ...

Arrangement of Events in an AngularJS Timeline

https://i.sstatic.net/qtUZb.jpgI am currently working with angularjs version 1.5.0 and I am trying to adjust the layout of my timeline so that all events are displayed on a single side. Does anyone have suggestions or solutions on how I can achieve this? ...

Instructions for inserting a hyperlink into a column of a table with the *ngFor directive in Angular2

I currently have a table with 4 columns: Name, ID, Department, and City. I am fetching both the row data and column data as an array from a TypeScript file and iterating through them using *ngFor. Below is a snippet of my code: <tbody> <tr *ng ...

Troubleshooting resizing images in React using Material UI's useStyles

When attempting to resize an image using React, I am encountering a problem where adjusting the height and width of the tag with useStyles does not reduce the size of the image but instead moves it around on the page. Here is the code snippet: import { ma ...

The issue of background color not displaying correctly inside a 'div' element

When trying to add a background color to a div with images, I can only achieve it by including the footer within the div, which is not ideal. I want the background-color to be applied only to the section inside the div. /* CSS */ div#gallery_contai ...