Guide to Styling List Items with Icons and Titles

Is it possible to align two elements to the left and two to the right within a list item (li)? The li is part of a page utilizing Bootstrap framework and FontAwesome project. You can see an example here: Below is the code for the li:

<li class="list-group-item d-flex justify-content-between align-items-center">
 <i class="fa fa-plus-square-o" aria-hidden="true"></i> Pay Car Insurance
 <i class="fa fa-pencil" aria-hidden="true"></i>
 <i class="fa fa-trash-o" aria-hidden="true"></i>
</li>

Answer №1

To customize your Bootstrap 4 layout without using additional CSS, simply apply the ml-auto class to the third element, specifically the pencil icon.

You can also enhance the design by adding some padding to the plus and pencil icons using the pr-3 class for both elements. It's that easy!

Check out the updated code snippet below:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<div class="container">
    <div class="row">
        <div class="add-item text-center col-sm-12 col-md-10 col-lg-8 mb-4">
            <h1 class="heading-4">Todo List Items</h1>
            <ul id="list" class="list-group mt-4 pb-4">
                <li class="list-group-item d-flex justify-content-between align-items-center">
                    <i class="fa fa-plus-square-o pr-3" aria-hidden="true"></i>Pay Car Insurance
                    <i class="fa fa-pencil ml-auto pr-3" aria-hidden="true"></i>
                    <i class="fa fa-trash-o" aria-hidden="true"></i>
                </li>
            </ul>
        </div>
    </div>
</div>

If you wish to convert those icons into clickable links, remember to include the ml-auto class within the anchor tag as shown in this modified code:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<div class="container">
    <div class="row">
        <div class="add-item text-center col-sm-12 col-md-10 col-lg-8 mb-4">
            <h1 class="heading-4">Todo List Items</h1>
            <ul id="list" class="list-group mt-4 pb-4">
                <li class="list-group-item d-flex justify-content-between align-items-center">
                    <a href="#"><i class="fa fa-plus-square-o pr-3" aria-hidden="true"></i></a>Pay Car Insurance
                    <a href="#" class="ml-auto pr-3"><i class="fa fa-pencil" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
                </li>
            </ul>
        </div>
    </div>
</div>

Answer №2

<li class="list-group-item  justify-content-between align-items-center">
    <i class="fa fa-plus-square-o left" aria-hidden="true"></i> 
    <span class="left marg_left">Renew Car Registration </span>
    <i class="fa fa-pencil right marg_left" aria-hidden="true"></i>
    <i class="fa fa-trash-o right  " aria-hidden="true"></i>
</li>

in css ::

.marg_left {
    line-height: 16px;
    margin-left: 12px;
}

.left {
    float: left;
}

.right {
     float: left;
}

.marg_right{
     margin-right:12px;
}

https://i.sstatic.net/dIabD.png

Answer №3

experiment with adding either class="pull-right" or class="pull-left"

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

Content not being displayed in Rails 4 with AJAX using Bootstrap 3 Modal

Despite researching several resources on BS modals with AJAX, such as the one found here: Bootstrap Modal in Rails Keeps displaying the first record, I am still encountering issues. Upon implementing AJAX (using JQuery 2.1.1), the modal successfully opens ...

What's the best way to arrange my containers for optimal placement?

I'm attempting to create a Thymeleaf template for rendering a printable PDF. Here is what I currently have: <html xmlns:th="http://www.thymeleaf.org" > <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" ...

Using CSS on a randomly selected div that is chosen after dividing the main div each time it is clicked

Imagine a square box displayed as a "div" element. When you click on it, it splits into an n x n grid with each square having a random background color. However, the issue I am encountering is that I want to apply additional CSS to each of these randomly c ...

Left-aligned Bootstrap carousel design

Recently, I've been working on tweaking this code to make it Bootstrap 4 compatible and left aligned. However, I'm encountering two persistent issues that I can't seem to resolve: The right side keeps getting cut off even though I intended ...

Contact form in Bootstrap 5 lacks responsiveness

I am currently exploring Bootstrap 5 for my website design project, and one of the features I have implemented is a contact form. While the white arrow that separates the two sections blends in seamlessly on desktop and laptop screens, it doesn't quit ...

Utilizing _.where() in underscore to perform case-insensitive value comparisons

I need help with a webpage feature that allows users to search for specific values in a file. However, I want the search functionality to be case-insensitive while keeping the original case sensitivity of the data in the file. Currently, I am using an und ...

Tips for troubleshooting Bootstrap Dropdown in a vertical navigation bar

Struggling to implement a vertical navigation bar with a dropdown menu on the third list item in Bootstrap 4, but facing issues as the dropdown options are not showing up. The template is specifically designed for an Angular component. I've gone thro ...

Using jQuery to update a table, however, the browser is failing to automatically refresh the

I have developed a node.js and sockets app to create a Single Page Application (SPA). The user can fill out a form to create a new lobby. Upon submission, a socket event is sent to the server, where the new lobby is added. The server then emits an event to ...

How can you prevent a draggable element from surpassing the bottom of the screen?

I'm dealing with an element that I want to make draggable only along the Y-axis. It needs to be able to go past the top of the screen, but I need to restrict it from going past the bottom of the screen. I recently came across the containment feature i ...

Animation for Bootstrap dropdowns fails to display in Internet Explorer and Firefox browsers

As I embark on creating my debut website using Bootstrap, I have incorporated a special CSS code snippet in my custom.css file to add an eye-catching animation to the dropdown menu in the navigation bar: .open > .dropdown-menu { -webkit-transform: sc ...

Looking for a way to align two child divs next to each other within a parent div? I've tried multiple methods, but none seem to be effective

Despite trying various methods like using inline-block and float, the divs in my code continue to stack on top of each other. What could be causing this issue? #resources { position: fixed; top: 0; left: 0; z-index: 1; display: block; wid ...

Why does the for loop assign the last iteration of jQuery onclick to all elements?

I've encountered an issue with my code that I'd like to discuss var btns = $('.gotobtn'); $('#'+btns.get(0).id).click(function() { document.querySelector('#navigator').pushPage('directions.html', myInf ...

Validate Bootstrap - Transmit data from all form fields to external PHP script

Is there a way to send all input field values to a remote PHP file using Bootstrap Validator? In my log in form, I have two input fields. I'm utilizing Bootstrap Validator's remote validation on both of them. However, each validation only sends ...

Is there a way to extract shared properties within a Material UI style declaration?

I am working with a specific set of style rules that define different statuses: status_in_progress: { fontSize: 14, backgroundColor: theme.palette.success.dark, padding: 2, paddingLeft: 5, paddingRight: 5, display: "inline-bl ...

display a different selection option depending on the previously chosen item

I'm working on displaying additional options in a select box when the user makes a selection from the main select box. I've set display:none for the select boxes, which will only appear when the user chooses an option from the main select box. C ...

Steps for creating a border around a container Div:1. Set the width and

Seeking assistance in bordering a div with 4 fa-icons inside. The parent div is named Container, and as a result, the border is creating excessive padding on the left and right sides horizontally. Attempted nesting bootstrap grids without success. Can anyo ...

Having trouble with printing the $length variable? Attempting to input data from duplicated forms

I have unique code presented below. In my HTML input tags, I have declared arrays named field, title[], first_name[], last_name[], email_address[], twitter_handle[]. These arrays were declared for form cloning purposes handled in a .js file. Now, my goal i ...

Ensure that the top border is aligned perfectly with the top of the page while keeping the text in its

I am a beginner student working on my very first project, so I appreciate your patience as I learn. Currently, I am trying to add a hover effect to the navigation bar links where a blue bar appears at the top of the link and touches the border of the page ...

Selenium was unable to find the p tag element on the webpage

I apologize for reaching out to you all for assistance with such a basic task, but I have tried everything in my toolkit and still can't seem to figure it out. I've experimented with partial xpath, full xpath, and various CSS selectors. I am see ...

Show large emoji as the background image of a jumbotron

Check out this incredible jumbatron I want to spruce it up by adding three random emojis on the right side like in this example I created using paint: how it should look Any suggestions on how I can achieve that? Here's a snippet of my CSS: .ju ...