Center a list-group with text and dropdown using Bootstrap 4 vertical alignment

I am relatively new to using Bootstrap 4 and I am encountering challenges in vertically aligning certain elements within a list-group. Specifically, I have text on the left side and a dropdown on the right.

<div class="dashboard-blocks">
  <ul class="list-group ">
    <li class="dashboard-block list-group-item">
      <span class="align-middle">Write Article/s</span>
      <span class="btn-group float-right">
        <button
          type="button"
          class="btn btn-secondary dropdown-toggle"
          data-toggle="dropdown"
          aria-haspopup="true"
          aria-expanded="false"
        >
          ACTION
        </button>
        <span class="dropdown-menu dropdown-menu-right">
          <button class="dropdown-item" type="button">Action</button>
          <button class="dropdown-item" type="button">
            Another action
          </button>
          <button class="dropdown-item" type="button">
            Something else here
          </button>
        </span>
      </span>
    </li>

Aside from basic font, color, and border styling in CSS, these are the adjustments I've made:

.dashboard-block {
 ...
  line-height: normal;
  letter-spacing: normal;
...
  padding: 25px;
  margin-top: 10px;
  margin-bottom: 10px;
}

The issue I'm facing is that "Write Article" is not perfectly aligned vertically: https://i.sstatic.net/1a2Wz.png

Answer №1

Utilize the flex utility to solve the issue of not being able to vertically center the span element due to .float-right.

<div class="dashboard-blocks">
    <ul class="list-group ">
        <li class="dashboard-block list-group-item d-flex justify-content-between align-items-center">
          <span class="align-middle">Write Article/s</span>
          <span class="btn-group">
            <button
              type="button"
              class="btn btn-secondary dropdown-toggle"
              data-toggle="dropdown"
              aria-haspopup="true"
              aria-expanded="false"
            >
              ACTION
            </button>

          </span>
        </li>
        </ul>
        </div>

Steps to follow:

  1. Add classes to <li>: .d-flex, .justify-content-between, .align-items-center
  2. Remove unnecessary classes .align-middle and .float-right from the span element.

Explore a Sample JS Fiddle: https://jsfiddle.net/srijan1709/apbmgde2/13/

Learn more about Bootstrap 4 Flex Utility: https://getbootstrap.com/docs/4.0/utilities/flex/

Answer №2

To center your text vertically within the SPAN element, simply apply this CSS style:

vertical-align: middle;

Best of luck with your styling!

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

Learn how to implement icons within Textfield components using Material-UI and TypeScript in React

I have successfully created a form with validation using TypeScript Material UI and Formik. Now, I am looking to enhance the visual appeal by adding a material UI Icon within the textfield area. Below is a snippet of my code: import React from 'reac ...

Looking for a substitute for iframes when using jQuery UI tabs?

I currently have a Spring-based web application that integrates with jQuery Tabs. What I'm doing is building a data string with specific parameters and appending it to a URL: var hrefData = "?" + item1 + "&" + item2 + "&" + item3; var href = ...

Automatic closure of Info Window on Google Maps is not functioning as expected

I have recently developed a map which you can view here. The issue I am facing is that when I click on the layers to see the InfoWindow, they do not automatically close when I click on another layer. The JavaScript code I am using is causing this problem. ...

Is there a way to sort a table using a dropdown menu selection as a filter?

I am currently working on a project that involves a table with three columns, which are typically populated from a SQL database. My goal is to filter the third column based on the value selected from a dropdown menu. I came across a helpful tutorial on W3 ...

Add JavaScript and CSS files from the node_modules folder to enhance a static HTML webpage

Currently, my development server is set up using node's live-server. However, for production, I plan to use a LAMP server. Within my node_modules directory, I have the normalize.css file. In my index.html, I currently link to it like this: <link ...

What is the best way to create a repeating Jquery loop in code?

Hey there! I've been working on creating a button that toggles the background color from white to yellow and back again using Jquery. However, I've hit a bit of a roadblock with implementing a loop function. If you'd like to take a look at m ...

Ways to align anchor tags in the middle of a DIV element?

<div style="border: 1px solid rgb(0, 0, 0); height: 30px; width: 30px; background-color: rgb(245, 225, 130);"> <div style="margin: 5px;"> <a href="#link">#down2#</a> </div> </div> This is the current code I am w ...

What is the best way to develop an expanding line animation from this starting point?

I have a vision for an animation where, upon hovering over an icon, it enlarges, increases in opacity, and reveals some accompanying text. The visual effect I am aiming for involves two lines of color expanding horizontally from the center outwards before ...

What are some common reasons why CSS and Bootstrap code can unexpectedly break?

I have been working on two tabs (tab-one, tab-two) where one is visible and the other is hidden. However, there has been an issue where the code breaks between the bottom of tab-one and the top of tab-two, causing some portion of tab-two to be occasionally ...

What is the best way to align a label, input box, and a small search image on the same line

I'm currently working on developing a mobile page using jQuery Mobile version 1.4.4. I've managed to get the label and input box to display correctly in one line, but I'm encountering an issue with the small search image appearing on the nex ...

Creating a multiline textarea with ellipsis using ReactJS

Looking to create a component with a multiline textfield that displays ellipsis (...) for text overflow beyond 2 lines. How can I achieve this through CSS only without modifying the actual stored text? Utilizing the React component found at: link Appreci ...

What is the best method for deleting an uploaded image from a box?

My code is quite lengthy, so I'll just showcase the JavaScript portion here. Here is a snippet of my JavaScript code: <script type="text/javascript"> let current = 0; for(let i = 0; i < 5; i++) { $('#thumbnail-view- ...

Problem with HTML produced by a loop

I am encountering difficulties when trying to create a collapsible list of elements. You can view my code on JSFiddle This is what my code looks like: <div class="projectscontainer"> <span class="item destproject" title="ID: 384">Kaoweuza ...

Having difficulty adjusting the margin-top for the menu div

Why am I unable to apply margin to my a links within the div identified by id="menu". I can successfully implement margin-left, but when attempting to use margin-top or margin-bottom, it does not work as expected. I wish to adjust the position o ...

Using NodeJS to fetch external page data and return Javascript variable information

I need to retrieve the entire DOM of a specific page by sending a request, essentially crawling the website. The HTML directly includes a variable with some data, instead of it being in a separate script file. With my NodeJS backend, I am utilizing request ...

My button is overflowing its container in Bootstrap 5, how can I fix this issue?

I've been experiencing an issue with the button in my code. It keeps extending outside of the parent div container, regardless of the screen size. <header class="header"> <div class="hero text-white pt-7"> <div ...

Safari is displaying CSS in a completely unique way

Working on my very first webpage using just HTML and CSS has been an interesting experience. After creating the first 2 pages and checking in Chrome and IE, I decided to test in Firefox and Safari. To my surprise, Safari rendered my CSS differently than e ...

How to use AngularJS directives to replace text with stars (*) in HTML

I am in need of a textarea control that has the ability to be masked, meaning that the text displayed should appear as stars instead of the actual characters. Since I might have multiple textareas in my form, saving the actual text in one variable and usi ...

The Bootstrap col-md class causes the label text to be truncated

I am encountering an issue where a label extends beyond a certain length and ends up being placed under other elements. Check out the image for reference: form input I would like the entire label text to be visible. I believe the col-md-1 class from boot ...

What steps can I take to stop search engines from crawling and indexing one specific page on my website?

I'm looking for a way to prevent search engines from indexing my imprint page. Is there a method to achieve this? ...