How can I float a fontawesome icon to the right and still have it vertically middle aligned? I've tried using ml-auto and Flexbox, but it's not working.
Here's my code:
<ul class="list-group flex-column">
<li class="list-group-item py-2 d-flex justify-content-start">
<a href="#">
<img src="https://placehold.it/40x40" height="40" class="mr-4">
<span>Text Here</span>
<i class="fa fa-angle-right ml-auto" aria-hidden="true"></i>
</a>
</li>
</ul>
Can someone help me out? Thanks!
Use the flex and sizing helper classes to make the link a flex parent with 2 children - the content you want on the left, and the content on the right. Use .justify-content-between, .align-items-center to separate the content so the arrow is on the right and centered vertically.
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="list-group flex-column">
<li class="list-group-item py-2 d-flex">
<a href="#" class="d-flex w-100 justify-content-between align-items-center">
<span>
<img src="https://placehold.it/40x40" height="40" class="mr-4">
<span>Text Here</span>
</span>
<i class="fa fa-angle-right ml-auto" aria-hidden="true"></i>
</a>
</li>
</ul>
Try with this structure:
<ul class="list-group">
<li class="list-group-item">
<a class="w-100 d-flex align-items-center py-2" href="#">
<img src="https://placehold.it/40x40" height="40" class="mr-4">
<span>Text Here</span>
<i class="fa fa-angle-right ml-auto" aria-hidden="true"></i>
</a>
</li>
</ul>
Click here to see it working in jsfiddle.
Your <a> tag doesn't fill the entire parent, so you can't see the effect of ml-auto on the icon. Also d-flex must be in the a tag, not in li.
Related
I am trying to fix these photos to be a tiny more centered. Maybe shift down a little and to the left. I am using all bootstrap and do not have any css attached to this. It is all working within the ul tags. Any help appreciated.
Page Screen Shot
<ul>
<li>
<a href="https://example.com" class="dropdown-header">
<strong>Example</strong><br />
<span class="megasubheader">| NEWS AND CONTENT </span>
</a>
</li>
<li class="dropdown-divider"></li>
<li class="list-group">
<a href="https://example.com" class="list-group-item mt-2" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<img id="imgsrc1" width="75px" height="75px" class="rounded mx-2">
<span id="Htitle1" style="font-size: 14px"></span>
</div>
</a>
<a href="https://example.com" class="list-group-item mt-2" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<img id="imgsrc2" width="75px" height="75px" class="rounded mx-2">
<span id="Htitle2" style="font-size: 14px"></span>
</div>
</a>
<a href="https://example.com" class="list-group-item mt-2" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<img id="imgsrc3" width="75px" height="75px" class="rounded mx-2">
<span id="Htitle3" style="font-size: 14px"></span>
</div>
</a>
</li>
</ul>
Use my-auto on your img element.
Would this help your situation ?
<div class="d-flex w-100 justify-content-between flex-row align-items-center">
<img id="imgsrc3" width="75px" height="75px" class="rounded me-2">
<span id="Htitle3" style="font-size: 14px"></span>
</div>
More over bootstrap spacing:
https://getbootstrap.com/docs/5.0/utilities/spacing/
I saw that your text is long, so that has an effect too on it, with less text for me it works fine. hope this helps.
<div class="card-body p-0">
<ul class="list-group list-group-flush">
<li class="list-group-item d-flex justify-content-between" th:each="extraConfig : ${extraConfigsPage.content}">
<div>
<a class="item-link">
<span class="item-name ml-2" th:text="${extraConfig.description}"></span>
</a>
</div>
<div>
<a class="btn btn-outline-danger" data-toggle="modal" data-target="#deleteReportModal">
<i class="fas fa-trash-alt"></i>
</a>
</div>
</li>
</ul>
</div>
This is my code. My problem is that the first item in the list (the first div) is not aligned in the center of the icon that exists in the same row. I want the first item to be aligned totally left and in the center of the row, and the second one to be aligned totally right and again in the center (with this code the second item is perfectly aligned).
I don't want to use extra CSS, I want to use only bootstrap classes.
Any ideas? Thanks in advance!
If you could add the bootstrap class align-baseline to your anchor tag for the icon, it will move the icon up to the center of the list item, and that should line up the icon with the center of your left-side tag:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/js/bootstrap.bundle.min.js"></script>
<div class="card-body p-0">
<ul class="list-group list-group-flush">
<li class="list-group-item d-flex justify-content-between">
<div>
<a class="item-link">
<span class="item-name ml-2">Fling</span>
</a>
</div>
<div>
<a class="btn btn-outline-danger align-baseline" data-toggle="modal" data-target="#deleteReportModal">
<i class="fas fa-trash-alt"></i>
</a>
</div>
</li>
</ul>
</div>
I removed the th: so the snippet has plain HTML and I added a word with a descender in the first tag for comparison.
Whenever I've to use a long section name inside a container with a list for a small column (col-2). My text is getting beneath my fontawesome icon as shown below. Thanks in advance!
PFB the HTML code:
<ul class="js-scroll-nav list-group list-group-transparent list-group-flush list-group-borderless py-3 px-3">
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#online">
<i class="fas fa-play-circle fa-lg"></i> List Item Apple Strudel
</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#discourses"><i class="fas fa-play-circle fa-lg"></i> List Item PumpkinStrudel
</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#disciple"><i class="fas fa-play-circle fa-lg"></i> List Item BerryStrudel</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#yogic"><i class="fas fa-play-circle fa-lg"></i> List Item CokeStrudel</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#events"><i class="fas fa-play-circle fa-lg"></i> List Item DoritosStrudel</a>
</li>
</ul>
How can I leave space below fontawesome icon so that my text on the second line populates exactly below from where my first text starts as shown below:
Don't use for spacing. Use padding/margin as appropriate.
What we want to do here is set the a element to have position:relative and the icon to be positioned absolutely within it. Then in the a element we set the left padding appropriately to indent the text.
Adjust the values below to taste. Perhaps add your own classes instead of overriding bootstrap classes directly.
a.list-group-item-action {
position: relative;
padding-left: 30px;
}
.list-group-item-action i.fas {
position: absolute;
left: 10px;
}
.list-group {
width:30%;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<ul class="js-scroll-nav list-group list-group-transparent list-group-flush list-group-borderless py-3 px-3">
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#online">
<i class="fas fa-play-circle fa-lg"></i>List Item Apple Strudel
</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#discourses"><i class="fas fa-play-circle fa-lg"></i>List Item PumpkinStrudel
</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#disciple"><i class="fas fa-play-circle fa-lg"></i>List Item BerryStrudel</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#yogic"><i class="fas fa-play-circle fa-lg"></i>List Item CokeStrudel</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#events"><i class="fas fa-play-circle fa-lg"></i>List Item DoritosStrudel</a>
</li>
</ul>
I have a project which is similar to the snippet below, except that it includes Material Design icons as described in https://materialdesignicons.com/getting-started.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<p>Contact us and we'll get back to you as soon as possible.</p>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<i class="mdi mdi-map-marker"></i>
<div>Av. St. Andreu 116, 08392 St. Andreu de Llavaneres, Spain</div>
</li>
<li class="list-group-item">
<i class="mdi mdi-phone"></i>
+34 937927406
</li>
<li class="list-group-item">
<i class="mdi mdi-email"></i>
<a href=mailto:ralf#peek.solutions>ralf#peek.solutions</a>
</li>
</ul>
With the icons, it looks like this:
As you can see, the icon is just 'a part of the text', I suppose because it is an inline element, and putting the address text in a div doesn't change this.
I would like to alter this appearance such that it looks more like a table so that when the address wraps to a new line it is left-aligned with the previous line. However, I'd still like to use Bootstrap 4's .list-group-flush for the 'row layout'.
What would be the best way to approach this? Should I make the li a flex box?
You can do so in pure bootstrap. Setting a negative margin for the i is a bad practice. Instead, you should remove the padding of li elements.
/* You may not need this line if you use material-design-icon */
.fas {
line-height: 1.5 !important;
}
<link href="https://use.fontawesome.com/releases/v5.0.7/css/all.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-4 mx-auto">
<ul class="list-group ">
<li class="list-group-item border-left-0 border-right-0 d-flex pl-0">
<i class="fas fa-map-marker-alt"></i>
<span class="pl-3">Av. St. Andreu 116, 08392 St. Andreu de Llavaneres, Spain</span>
</li>
<li class="list-group-item border-left-0 border-right-0 d-flex pl-0">
<i class="fas fa-phone"></i>
<span class="pl-3">+34 937927406</span>
</li>
<li class="list-group-item border-left-0 border-right-0 border-bottom-0 d-flex pl-0">
<i class="fas fa-envelope"></i>
<a class="pl-3" href=mailto:ralf#peek.solutions>ralf#peek.solutions</a>
</li>
</ul>
</div>
</div>
</div>
I indeed managed to get the desired layout by making the li a flex box. Adding div elements to all the text,
<p>Contact us and we'll get back to you as soon as possible.</p>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<i class="mdi mdi-map-marker"></i>
<div>Av. St. Andreu 116, 08392 St. Andreu de Llavaneres, Spain</div>
</li>
<li class="list-group-item">
<i class="mdi mdi-phone"></i>
<div>+34 937927406<div>
</li>
<li class="list-group-item">
<i class="mdi mdi-email"></i>
<div><a href=mailto:ralf#peek.solutions>ralf#peek.solutions</a><div>
</li>
</ul>
and adding the following CSS,
li.list-group-item {
display: flex;
}
li.list-group-item i {
margin-left: -20px;
}
li.list-group-item div {
margin-left: 10px;
}
makes the contact info look like this:
I have a li (list item) which contains four elements. 2 of the elements I would like to align to left and the other 2 to the right. The li is part of a page using the Bootstrap framework and FontAwesome project: http://pctechtips.org/apps/todo/
Here's 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>
The only thing you need to do in your case (to make it work with native Bootstrap 4 classes only and without any css hacking) is to add the ml-auto (margin-left:auto) class to the third element i.e. the pencil icon.
Then you just add a bit of padding to the plus and the pencil icon by adding the pr-3 (padding-right) class to both. That's it!
Here's the working 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">
<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>
And if you want to turn those icons into links, you'll need to add the ml-auto class to the anchor like so:
<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" aria-hidden="true"></i>
<i class="fa fa-trash-o" aria-hidden="true"></i>
</li>
</ul>
</div>
</div>
</div>
<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">Pay Car Insurance </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;
}
you can try add class="pull-right" or class="pull-left"