I'm using Tailwind CSS along with Font Awesome Icons. Here the icons show like this,
Is it not suitable to adjust every div's width. Here is my code (For an element),
<!-- Navigation Link-->
<div class="w-100 p-3 hover:bg-white/30">
<div class="flex gap-4 text-white-max pl-3">
<div>
<i class="fas fa-tags"></i>
</div>
<div>Products</div>
</div>
</div>
<!-- End Navigation Link-->
My question is how to adjust this without changing every single element.
Add fa-fw class to the icon, see more info about Fixed Width Icons
Add a class of fa-fw on the HTML element referencing your icon to set one or more icons to the same fixed width.
console.clear()
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/js/all.min.js"></script>
<div class="w-100 p-3 hover:bg-white/30">
<div class="flex gap-4 text-white-max pl-3">
<div>
<i class="fas fa-tags fa-fw"></i>
</div>
<div>Products</div>
</div>
<div class="flex gap-4 text-white-max pl-3">
<div>
<i class="fa-brands fa-fw fa-windows"></i>
</div>
<div>Dashboard</div>
</div>
</div>
FontAwesome has a class for this fa-fw which will make an icon square, this is applied to each icon along with the variant and name class, so like fa-solid fa-fw fa-file-lines for example
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/js/all.min.js"></script>
<div class="text-white bg-stone-900 inline-flex flex-col" style="--fa-animation-duration: 1.5s; --fa-animation-iteration-count: 3; --fa-animation-timing: ease-in-out">
<div class="cursor-pointer p-3 hover:bg-white/30">
<div class="flex items-center gap-3 px-3">
<i class="fa-brands fa-fw fa-windows fa-beat"></i>
Dashboard
</div>
</div>
<div class="cursor-pointer p-3 hover:bg-white/30">
<div class="flex items-center gap-3 px-3">
<i class="fa-solid fa-fw fa-file-lines fa-beat"></i>
Documents
</div>
</div>
<div class="cursor-pointer p-3 hover:bg-white/30">
<div class="flex items-center gap-3 px-3">
<i class="fa-solid fa-fw fa-tags fa-beat"></i>
Products
</div>
</div>
<div class="cursor-pointer p-3 hover:bg-white/30">
<div class="flex items-center gap-3 px-3">
<i class="fa-solid fa-fw fa-cube fa-beat"></i>
Stock
</div>
</div>
</div>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/js/all.min.js" integrity="sha512-6PM0qYu5KExuNcKt5bURAoT6KCThUmHRewN3zUFNaoI6Di7XJPTMoT6K0nsagZKk2OB4L7E3q1uQKHNHd4stIQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<div class="w-100 p-3 hover:bg-white/30">
<div class="flex gap-3 text-white-max pl-3">
<div>
<i class="fa-brands fa-fw fa-windows"></i>
</div>
<div>Dashboard</div>
</div>
<div class="flex gap-3 text-white-max pl-3">
<div>
<i class="fa-solid fa-fw fa-file-lines"></i>
</div>
<div>Documents</div>
</div>
<div class="flex gap-3 text-white-max pl-3">
<div>
<i class="fa-solid fa-fw fa-tags"></i>
</div>
<div>Products</div>
</div>
<div class="flex gap-3 text-white-max pl-3">
<div>
<i class="fa-solid fa-fw fa-cube"></i>
</div>
<div>Stock</div>
</div>
</div>
Related
I need to have a screen that has top bar as a menu, that is a ul of my-10, and the rest of the screen is a div with a background image. Together they should cover h-screen.
What classes should I give to the nav, and what to the div containing the image?
Thanks
You can achieve this by display type of flex.
For your scenario:
Use a navand a div which is inside the parent element of flex flex-col h-screen
And then give following classes for nav and div
nav -> flex
div -> flex-1
Try the following simple code:
<div className="flex flex-col h-screen">
<nav class="flex items-center justify-between bg-white h-20 shadow-2xl">
<div class="logo">
<h1 class="text-black ml-4 cursor-pointer text-2xl">Logo here</h1>
</div>
<ul class="flex">
<li>
<a
class="text-white mr-4 bg-gray-500 pt-4 p-4 pr-5 pl-5 hover:bg-gray-600 transition-all rounded"
href="#"
>
<i class="fas fa-home"></i> Home
</a>
</li>
<li>
<a
class="text-white mr-4 bg-gray-500 pt-4 p-4 pr-5 pl-5 hover:bg-gray-600 transition-all rounded"
href="#"
>
<i class="fas fa-question"></i> About
</a>
</li>
<li>
<a
class="text-white mr-4 bg-gray-500 pt-4 p-4 pr-5 pl-5 hover:bg-gray-600 transition-all rounded"
href="#"
>
<i class="fas fa-reply"></i> Contact
</a>
</li>
</ul>
</nav>
<div className="flex-1 bg-black">
<img
src="https://mdbootstrap.com/img/new/slides/041.jpg"
className="min-w-full min-h-full"
alt="..."
/>
</div>
</div>
Output:
For more information about the flex class refer https://tailwindcss.com/docs/flex
When I add the class float-end it pushes the button to right but the div tags next to that comes front of it.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="col-md-7 bg-white shadow-sm rounded-3 mx-3 ">
<div>
<a href="#" class="btn btn-sm btn-primary m-2 mr-0">
Edit <i class="bi bi-pencil"></i>
</a>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Pan no</div>
<div class="text-secondary">not added</div>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Birthdate</div>
<div class="text-secondary">not added</div>
</div>
</div>
I fixed it by adding the "clearfix" class to button's parent div.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="col-md-7 bg-white shadow-sm rounded-3 mx-3 ">
<div class="clearfix">
<a href="#" class="btn btn-sm btn-primary m-2 mr-0">
Edit <i class="bi bi-pencil"></i>
</a>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Pan no</div>
<div class="text-secondary">not added</div>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Birthdate</div>
<div class="text-secondary">not added</div>
</div>
</div>
Here, in the overview section
Float - Bootstrap v5.0
Please be aware float utilities have no effect on flex items.
Note that float will will make it pop to the left-most or right-most position in the parent element. so you must add clearfix to the parent element.
Hello I have two options for you
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- one options -->
<div class="col-md-7 bg-white shadow-sm rounded-3 mx-3 ">
<div class="position-relative">
<div class="position-absolute top-0 end-0">
<a href="#" class="btn btn-sm btn-primary m-2 mr-0">
Edit
</a>
</div>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Pan no</div>
<div class="text-secondary">not added</div>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Birthdate</div>
<div class="text-secondary">not added</div>
</div>
</div>
<br>
<!-- two options -->
<br>
<div class="col-md-7 bg-white shadow-sm rounded-3 mx-3 ">
<div class="float-start col-10 p-2">
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Pan no</div>
<div class="text-secondary">not added</div>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Birthdate</div>
<div class="text-secondary">not added</div>
</div>
</div>
<div class="float-end col-2 p-2">
<a href="#" class="btn btn-sm btn-primary d-flex justify-content-center align-self-center">
Edit
</a>
</div>
<div class="float-start col-12 p-2">
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Addres</div>
<div class="text-secondary">not added</div>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">Zip Code</div>
<div class="text-secondary">not added</div>
</div>
<div class="d-flex p-2 justify-content-between border-bottom">
<div class="fw-bold">City</div>
<div class="text-secondary">not added</div>
</div>
</div>
</div>
I have created a structure for a header and a sticky top navbar.
When we scroll down (medium screen and up), there is always a space line between my header and my navbar. We can see the body in that space.
Picture of the thin space line in yellow
I saw this come from the 3 buttons because when we deleted them, the space disapears but I don't know how to solve the problem.
Any idea ?
Please find my code
Thank you
SOLVED
The problem came from the a class bottom border. I think they didn't fit in the parent element.
Code after correction
HTML
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<section>
<div class="container-fluid bg-danger">
<div class="row">
<div class="col-md-6 my-auto">
<a class="d-flex justify-content-center align-items-center" href="#">
<h1 class="text-center"><span class="ft-color-1">BRAND NAME</span></h1>
</a>
</div>
<div class="col-md-6 p-2">
<ul>
<li>Adress, city</li>
<li>Ouvert 7/7 de 7h à 21h</li>
</ul>
<div class="d-none d-md-flex flex-row mb-2">
<a class="btn p-1 mr-1 w-100 bg-primary text-left" href="" role="button"> Itinéraire</a>
<a class="btn p-1 mr-1 w-100 bg-primary text-left" href="" role="button"> Contact</a>
<a class="btn p-1 mr-0 w-100 bg-primary text-left" href="" role="button"> Suivez-nous</a>
</div>
</div>
</div>
</div>
</section>
<nav class="navbar navbar-expand-md sticky-top bg-primary" id="navigation-barre">
<a class="navbar-brand text-white" href="#"> Brand name</a>
</nav>
<section class="bg-warning">
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</section>
I am using Angular 7 + Bootstrap. I am using bootstrap card deck to create 3 menus.
When the routerlinkactive is active, I want to style the border for that particular card, where the link is available.
<div class="container-fluid">
<div class="card-deck mb-3 text-center">
<div class="card mb-4 box-shadow"> <!-- want to style at this level when link is active -->
<div class="card-header pb-2">
<h4 class="my-0 font-weight-normal">Menu 1</h4>
</div>
<div class="card-body">
<a routerLinkActive="active" routerLink='my-courses' class="link-unstyled">
<i class="fas fa-tasks fa-9x"></i></a>
</div>
</div>
<div class="card mb-4 box-shadow">
<div class="card-header pb-2">
<h4 class="my-0 font-weight-normal">Menu 2</h4>
</div>
<div class="card-body">
<a routerLinkActive="active" routerLink='completion-certs' class="link-unstyled">
<i class="fas fa-award fa-9x"></i></a>
</div>
</div>
<div class="card mb-4 box-shadow">
<div class="card-header pb-2">
<h4 class="my-0 font-weight-normal">Menu 3</h4>
</div>
<div class="card-body">
<a routerLinkActive="active" routerLink='self-certification' class="link-unstyled">
<i class="fas fa-book-reader fa-9x"></i></a>
</div>
</div>
</div>
</div>
You can use something like this.
<a #rla="routerLinkActive" routerLinkActive="active" routerLink='my-courses' class="link-unstyled">.... </a>
and on the card div you can use [class.active-card]="rla.isActive"
Good day, I'm using Font-awesome and bootstrap 4. Please check my Script first
<div class="container">
<div class="row">
<div class="col">
<div class="row">
<span class="fa fa-building fa-5x text-center"> </span>
</div>
<div class="row">
<h3 class="text-center">Company Profile</h3>
</div>
</div>
<div class="col">
<div class="row">
<span class="fa fa-shopping-cart fa-5x text-center"> </span>
</div>
<div class="row">
<h3 class="text-center">Shopping Cart</h3>
</div>
</div>
<div class="col">
<div class="row">
<span class="fa fa-industry fa-5x text-center"> </span>
</div>
<div class="row">
<h3 class="text-center">Inventory Control</h3>
</div>
</div>
<div class="col">
<div class="row">
<span class="fa fa-users fa-5x text-center"> </span>
</div>
<div class="row">
<h3 class="text-center">User Management</h3>
</div>
</div>
</div>
</div>
with my script above i get this
as you can see, the fa icons is not at the center of text. How can i make the fa-icon in center ?
Add the text-center class to the div surrounding your icon instead of of the icon span like so:
<div class="row text-center">
<span class="fa fa-users fa-5x"> </span>
</div>
You can simplify your HTML markup to the below and the text under icons will be center aligned based on the class text-center assigned to parent col div.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<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="col-md-3 text-center">
<span class="fa fa-building fa-5x"> </span>
<h3>Company Profile</h3>
</div>
<div class="col-md-3 text-center">
<span class="fa fa-shopping-cart fa-5x"> </span>
<h3>Shopping Cart</h3>
</div>
<div class="col-md-3 text-center">
<span class="fa fa-industry fa-5x"> </span>
<h3>Inventory Control</h3>
</div>
<div class="col-md-3 text-center">
<span class="fa fa-users fa-5x"> </span>
<h3>User Management</h3>
</div>
</div>
</div>
Simply add the "text-center" class to the "fa" element container:
from:
<div class="row">
<span class="fa fa-building fa-5x text-center"> </span>
to:
<div class="row text-center">
<span class="fa fa-building fa-5x text-center"> </span>
Simply you can add one custom class for making those icons to center align.
You can check this fiddle.
.icon-center{
margin:0 auto;
}