Any ideas on how I can vertically align to the middle in my situation?

I'm experimenting with modifying HTML elements to achieve two specific goals:

  1. Trying to vertically align two glyphicons and texts in the middle. (The "vertical align middle" method isn't working as intended)

  2. Looking to adjust the CSS to create a small gap between the text "thanks" and glyphicons, aiming for a layout like

    <icon><thanks><icon>
    instead of
    <icon>   <thanks>   <icon>

I've set up a JSFiddle here: https://jsfiddle.net/vwdhd1wy/

I noticed an unexpected gap without any extra CSS added. Any assistance on this matter would be greatly appreciated!

Answer №1

Check out the code in action at: https://jsfiddle.net/vwdhd1wy/4/

To vertically align two glyphicons and texts to the middle, you need to ensure consistent CSS styling. Add vertical-align: top; to all span elements to keep them aligned correctly. It's important to override any conflicting inherited styles from .glyphicon, such as line-height: 1 and top: 1px;. Update these with

div > span.glyphicon { line-height: 30px; top: 0px; }
along with setting height: 30px; and line-height: 30px;.

div > span {  
  display: inline-block;
  vertical-align: top;  
}

div > span, div > span.glyphicon { 
  height: 30px;
  line-height: 30px; 
  top: 0px;
}

.left, .right {
  background-color: red;  
}

.middle {
  background-color: grey; 
}

To create a small gap between the text "thanks" and glyphicons, eliminate any whitespace after the span elements. This prevents extra space caused by treating inline elements as inline-block which includes spaces when rendering HTML.

Try this updated format:

<span class="left glyphicon glyphicon-forward"></span><span class="middle">Thanks</span><span class="right glyphicon glyphicon-backward"></span>

Answer №2

This solution is tailored to your specific needs.

   <div>
       <span class="left glyphicon glyphicon-forward"></span>
       <span class="middle">Appreciate</span>
       <span class="right glyphicon glyphicon-backward"></span>
    </div>

Now, let's enhance the styling further:

  .left {
      background-color: red;
      height: 30px;
    }

    .middle {
      height: 30px;
      display:inline-block;
      background-color: grey;
      vertical-align: middle;
    }

    .right {
      background-color: red;
        height: 30px;
    }
    span {
       align-items: center;
       display: inline-flex !important;
       flex-wrap: wrap;
    } 

Answer №3

Kindly utilize the following HTML and CSS code snippet:

<div class="centered">
   <span class="left-arrow glyphicon glyphicon-forward"></span>
   <span class="middle-text">Thanks</span>
   <span class="right-arrow glyphicon glyphicon-backward"></span>
</div>


    .centered{display:table;}
    .left-arrow {
      background-color: blue;
      height: 30px;
      vertical-align:middle;
       display:table-cell;
    }

    .middle-text {
      height: 30px;
      display:table-cell;
      background-color: lightblue;
      vertical-align:middle;
    }

    .right-arrow {
      background-color: blue;
        height: 30px;
        vertical-align:middle;
         display:table-cell;
    }

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

How can I achieve both horizontal and vertical centering simultaneously?

UPDATE: Seeking advice on aligning a rangeslider and its label vertically within the same row. The goal is to have them centered with respect to each other while ensuring the rangeslider takes up all available space. How can I vertically center a floatin ...

What is the best way to create a never-ending horizontal animation that moves a logo image from right

I have a dilemma with displaying my logo images. I have more than 10 logos, but I want to showcase only 6 of them on page load. The rest of the logos should slide horizontally from right to left in an infinite loop. Can anyone assist me with creating keyf ...

Using jQuery to extract a specific portion of a URL path

Seeking assistance with extracting category information from lengthy URLs and assigning it to a variable. Consider the following URL: http://example.com/community/home/whatever.html The goal is to assign the variable to the folder path that follows /hom ...

Ways to conceal table rows depending on their content

I am currently developing a project using Angular 2. One of the features includes a summary section that consolidates all the data from other sections. The summary is presented in a table format, with each row displaying the field name in the first colum ...

How to toggle the display of a div by its id using index in Javascript

Currently, I am encountering a problem with toggling the div containers. When I click on the video button, I want the other divs to close if they are already open. However, due to the toggling mechanism, if a div is closed and I click on the corresponding ...

"Having trouble getting `justify-between` to work in a tailwind CSS on an absolute

I'm currently using Tailwind CSS and I'm trying to position my navbar on top of an image. The image is set in a relative position and the navbar is set in an absolute position. Surprisingly, when the navbar is not set in the absolute position, I ...

Guide on how to forward the response obtained from an Ajax call to a different HTML page

I am working with a mongoose database that stores data containing an individual's first and last name. The user inputs their first name into a field, triggering an ajax request sent to the file named controller.js. This file generates a JSON response ...

The bootstrap carousel seems to be malfunctioning and instead displaying as background images

As someone who is new to coding, I have been attempting to create a slider on Bootstrap, but it seems to be displaying more like a background than an actual slider. Here is an excerpt of my HTML code: <body> <div class="navbar navbar-default ...

Unnecessary scrollbar appears in the Simple Material UI dialog demonstration

My Material UI dialog consists of a grid with a scrollbar that allows scrolling even though the content fits on the screen. <Dialog open={isOpen} onClose={() => changeIsOpen(false)}> <DialogContent> <Grid containe ...

Challenges with Processing Forms Using jQuery

Having trouble processing the data from my html form using jQuery. Below is the simple form: <form id="singup"> <input type="text" placeholder="Full Name" id="signup-name"> <input type="email" placeholder="Email Address" id="signup-emai ...

Problems with Displaying Facebook Ads on Mobile Web

Currently, I am incorporating Facebook Audience Network (MobileWeb-beta) for advertisements on my mobile website. However, the 320x50 HTML source code is not displaying the ad across the width of the mobile screen as intended; instead, it appears smaller ( ...

What is the best approach for testing an HTML element that does not have distinct attributes?

Currently, I am utilizing Coded UI Test to conduct tests on a web application. In my workflow, I rely on a class called Locator to store specific information necessary for CUIT to locate a control. When it comes to interacting with a control, a page objec ...

using selenium to locate elements that have a particular attribute

Is there a way to extract the text inside the red rectangles within each <div class='c', id='M_D....'> found in the image below? I attempted to use this code snippet: browser.find_element_by_xpath("//*[@class='ctt&a ...

What is the best way to locate an element with the class name being an email address using jQuery?

Is it possible to locate an element with an email address as the class name, considering that the email address varies? $(document).ready(function(){ //not working getting error var email="<a href="/cdn-cgi/l/email-protection" class="__cf_email__ ...

Align the dimensions of the table to match with the background image in a proportional

Seeking a contemporary method to match a table with a background image, ensuring all content scales proportionally. Mobile visibility is not a concern for this specific project. Using Wordpress with a starter bootstrap theme. Check out the code on jsfidd ...

The curly braces in AngularJS are failing to display the values on the HTML page

After trying various articles and solutions to different questions, I am still unable to resolve my issue. I am working on a blank ionic project and it is running smoothly in my browser using ionic serve without any errors. However, instead of displaying ...

Unknown error detected in Ajax URL connection

<html> <head> <meta charset="utf-8"/> <script src="../JQUERY/jquery-1.11.0.js"></script> <script> function fetchMenuOptions() { var html = ""; $.ajax( { //url: 'http://server.com/?method=get&a ...

Struggling to align my overlay accurately by combining absolute and relative positioning

I'm currently tackling a frontend mentor project, and I've hit a roadblock trying to get my image overlay to position itself over the image rather than below it. I've set the parent position to relative and the overlay to absolute, but so fa ...

Looking for a way to identify when a DOM element is resized as a result of web fonts loading asynchronously?

Within this div element lies text styled with a custom font via CSS's @font-face attribute. The issue arises when the font hasn't loaded yet, causing a delay in updating the font style of the text within the div. As a result, taking measurements ...

The CSS :not selector does not work as intended

My goal is to assign the class no-color to a specific tag. When JavaScript is enabled, I want this class to be removed and the text to be colorized. However, my current CSS solution is not working as expected. Below is a sample code snippet demonstrating t ...