Bootstrap - How to create a small dropdown - html

I want to create a small Bootstrap dropdown, But I don't know how, Here's what it looks like
base.html:
<a class="text-light" data-bs-toggle="dropdown" aria-expanded="false">
<svg width="12" height="14" fill="currentColor" class="bi bi-three-dots-vertical" viewBox="0 0 16 16">
<path d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/>
</svg>
</a>
<ul class="dropdown-menu dropdown-menu-dark bg-dark">
<li><a class="dropdown-item text-light" href="#">edit</a></li>
<li><a class="dropdown-item text-warning" href="#">report</a></li>
<li><hr class="dropdown-divider border-top border-secondary"></li>
<li><a class="dropdown-item text-danger" href="#">delete</a></li>
</ul>

As Cervus camelopardalis said in their answer, you should modify the dropdown since Bootstrap doesn't offer different sizes. I've just tried to make the dropdown look like the screenshot you posted as much as I could.
Since your code has some problems, I just used the official dropdown from Boostrap site. This is the latest version, I'll try to explain everything I did.
.btn {
width: 30px !important;
height: 30px !important;
padding: 0 !important;
border: none !important;
}
.dropdown-menu {
min-width: 100px !important;
}
.dropdown-item {
padding: 0px 5px !important;
font-size: 12px !important;
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="dropdown">
<button class="btn" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<svg width="12" height="14" fill="currentColor" class="bi bi-three-dots-vertical" viewBox="0 0 16 16">
<path d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/>
</svg>
</button>
<ul class="dropdown-menu dropdown-menu-dark bg-dark">
<li><a class="dropdown-item" href="#">edit</a></li>
<li><a class="dropdown-item text-warning" href="#">report</a></li>
<li><hr class="dropdown-divider border-top border-secondary"></li>
<li><a class="dropdown-item text-danger" href="#">delete</a></li>
</ul>
</div>
First of all, beside every CSS class, I added !important to override Bootstrap default stuff. In production, you should add your CSS file above Bootstrap CSS and then remove !important.
In the .btn class, I changed the width and height to 30px to change the size of the three dots button, also I removed padding as well as the borders to make it look nicer as the screenshot.
Thanks for Cervus camelopardalis, I used the same code to change the dropdown menu size.

Related

How to stop navbar from changing size

Basically have the right section of the navbar reserved for text/an alert that will be placed there depending on if certain things happen. But, the alert, even when invisible, changes the height of the navbar. How do I fix this?
It might be hard to tell with the images but there's definitely a difference with the popup and when it's closed.
This is using the latest bootstrap v5.2.3
.navbar-brand img {
height: 50px;
width: 50px;
}
.alert svg {
height: 20px;
width: 20px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" />
<nav class="navbar navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="#">
<img src="https://via.placeholder.com/100" alt="Bootstrap" width="30" height="24">
</a>
<span class="navbar-text text-dark" id="wallet_address">
<div class="alert alert-warning d-flex align-items-center alert-dismissible fade show" role="alert">
<svg xmlns="http://www.w3.org/2000/svg" class="bi bi-exclamation-triangle-fill flex-shrink-0 me-2" viewBox="0 0 16 16" role="img" aria-label="Warning:">
<path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
</svg>
<div>
<strong>ERROR!</strong> No Wallet detected.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</div>
</span>
</div>
</nav>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/js/bootstrap.bundle.min.js"></script>
edit: updated css and bootstrap version
It doesn't look like the alert is affecting anything while it's invisible. The alert has 1rem of margin on the bottom, which calculates out to make the entirety of the alert 90px tall. The available space of the nav by default is less than 90px, so including the alert in that space forces the nav to expand to accommodate the alert. Note the yellow area (margin) in the image.
The reason your nav has a height larger than expected when the alert is missing is because the navbar-brand class has some top and bottom padding, probably coming from bootstrap. Note the purple area (padding) in the image.

I seem to be having an issue with navigation bar turning in-to random colors that I've not set

Alright, so my navigation bar used to be looking like this a few days ago:
But once I try to center the navigation bar to the middle, it turns in-to random colors and the spaces between the interactable buttons disappeared as shown in this picture:
I just tried to debug it and apparently it only happens when I put the display to inline-block. Am I doing anything wrong?
My CSS for the navigation bar:
.topnav {
background-color: #ffffff;
overflow: hidden;
}
.topnav a {
float: center;
color: #000000;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
My HTML for the navigation bar:
<div class="topnav">
<i class="fab fa-facebook-square" style="font-size: 30px"></i>
<i class="fa-solid fa-book" style="font-size: 30px"></i>
<i class="fa-solid fa-pen-to-square" style="font-size: 30px"></i>
<i class="fa-solid fa-user-graduate" style="font-size: 30px"></i>
<i class="fa-solid fa-house-chimney" style="font-size: 30px"></i>
</div>
I removed the links for security reasons.
this happens because the <svg> if nested inside <a> will behave like a link...
you know that a link with a text inside is always blue and with an underline
just color the SVG to the color you want, to solve the bug
I created a demo in a jfiddle, so you can try and learn :)
I hope it will help you, and learned something new
body svg {
width: 5em;
}
/* color the svg, for not having this bug */
.with-success svg {
color: black;
}
<div class="with-error">
<h2>with error</h2>
<!-- 1 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
<!-- 2 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
</div>
<hr>
<div class="with-success">
<h2>success</h2>
<!-- 1 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
<!-- 2 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
</div>

Bootstrap 5 mobile Dropdown not sliding while clicking

Few things to know before starting:-
I'm using Django (python)
I'm using Bootstrap
And Obviously I'm using html and css
What I did (in order, when before I got an error):
I copied the navbar template from the bootstrap navbar docs
I linked my own custom css and js file from the static directory of django in the following order below:-
Javascript Files
(Copied from Bootstrap, so don't mind the comments) :)
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="{% static '/js/script.js' %}" type="text/javascript"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0"
crossorigin="anonymous"
></script>
Css Files
<link rel="stylesheet" href="{% static 'css/styles.css'%}" />
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl"
crossorigin="anonymous"
/>
Code in main html file
{%load static%}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{% static 'css/styles.css'%}" />
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl"
crossorigin="anonymous"
/>
<title>{%block title%} {%endblock %}</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img
src="{% static '/img/Socklet-logos.jpeg' %}"
alt="error in loading static files, may encounter bad design"
id="brand-logo"
class="float-start"
/>
<h1 id="brand">{%block brand%}{%endblock%}</h1></a
>
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div
class="collapse navbar-collapse"
id="navbarSupportedContent navbar"
>
<ul class="navbar-nav me-auto mb-2 mb-lg-0" id="navigation-bar">
<li class="nav-item" id="nav">
<a
class="nav-link active"
aria-current="page"
href="#"
id="nav-link"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
class="bi bi-house-door"
viewBox="0 0 16 16"
class="nav-icon"
>
<path
d="M8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4.5a.5.5 0 0 0 .5-.5v-4h2v4a.5.5 0 0 0 .5.5H14a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146zM2.5 14V7.707l5.5-5.5 5.5 5.5V14H10v-4a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5v4H2.5z"
/>
</svg>
Home</a
>
</li>
<hr style="color: white" />
<li class="nav-item" id="nav">
<a class="nav-link" id="nav-link" href="#">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
class="bi bi-kanban-fill"
viewBox="0 0 16 16"
class="nav-icon"
>
<path
d="M2.5 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2h-11zm5 2h1a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-1a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1zm-5 1a1 1 0 0 1 1-1h1a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1h-1a1 1 0 0 1-1-1V3zm9-1h1a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-1a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z"
/>
</svg>
Projects</a
>
</li>
<hr style="color: white" />
<li class="nav-item dropdown" id="nav">
<a
class="nav-link dropdown-toggle"
href="#"
id="navbarDropdown"
role="button"
data-bs-toggle="dropdown"
aria-expanded="false"
id="nav-link"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
class="bi bi-three-dots"
viewBox="0 0 16 16"
class="nav-icon"
>
<path
d="M3 9.5a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm5 0a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm5 0a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3z"
/>
</svg>
More
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Book Club</a></li>
<li><a class="dropdown-item" href="#">Blog</a></li>
<li><hr class="dropdown-divider" /></li>
<li>
<a class="dropdown-item" href="#">Our Employees</a>
</li>
</ul>
</li>
</ul>
<div class="d-flex">
<a href="{{login_logout_link}}">
<button
class="btn btn-outline-success"
name="login"
id="login-btn"
>
{{login_logout}}
</button>
</a>
</div>
</div>
</div>
</nav>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="{% static '/js/script.js' %}" type="text/javascript"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0"
crossorigin="anonymous"
></script>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.6.0/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/js/bootstrap.min.js" integrity="sha384-nsg8ua9HAw1y0W1btsyWgBklPnCUAFLuTMS2G72MMONqmOymq585AcH49TLBQObG" crossorigin="anonymous"></script>
-->
</body>
</html>
Code in custom Css file
#media screen and (max-width: 767px) {
.nav-icon {
height: auto;
width: auto;
max-height: 40px;
max-width: 140px;
}
}
#media screen and (min-width: 768px) {
.nav-icon {
height: auto;
width: auto;
max-height: 50px;
max-width: 125px;
}
}
#nav {
font-size: 30px;
}
#nav:hover {
background-color: black;
text-shadow: 500px;
}
#login-button {
align-items: right;
}
#brand:hover {
color: black;
}
#login-btn {
height: 45px;
width: 100px;
}
#nav-link {
padding: 10px;
}
svg {
height: 30px;
width: 30px;
}
#media (min-width: 767px) {
#brand {
padding-right: 250px;
font-size: 50px;
}
#brand-logo {
padding-right: 10px;
height: auto;
width: auto;
max-width: 250px;
max-height: 90px;
}
}
#brand-logo {
height: auto;
width: auto;
max-width: 100px;
max-height: 55px;
padding-right: 5px;
}
#navigation-bar {
align-items: center;
}
But here's the final output with a gif in which I'm clicking the dropdown but it doesn't slide:-
The id on:
<div
class="collapse navbar-collapse"
id="navbarSupportedContent navbar"
>
Must have the same value as data-bs-target="#navbarSupportedContent". That's how the button and the dropdown <div> are linked.
Try changing it to id="navbarSupportedContent"

Bootstrap align svg in center of header

I copied this card template from bootstrap for a warning card. At the header of the card, I'm using an svg that I got from Bootstrap's icons https://icons.getbootstrap.com/icons/exclamation-triangle-fill/. There, you can see some examples where the icon is implemented properly. The icon is aligned exactly in the middle next to the next. However, in my code the icon is aligned at the bottom and so is not centered. Is there a way to fix this?
<div class="card" style="width: 18rem;">
<div class="card-body">
<div class="mb-3">
<h5 class="card-title">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 5zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/>
</svg>
Warning
</h5>
</div>
<p class="card-text">
Text of card
</p>
</div>
</div>
Use negative margin-top to adjust it.
For example:
<div class="card" style="width: 18rem;">
<div class="card-body">
<div class="mb-3">
<h5 class="card-title">
<svg class="myIcon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 5zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/>
</svg>
Warning
</h5>
</div>
<p class="card-text">
Text of card
</p>
</div>
</div>
CSS:
.myIcon { margin-top: -5px; }
Check it here: https://jsfiddle.net/8t61qehn/
printf("%d\n", 42); /* You can simply add some css on style part in as follows: */
.card-svg {
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
}
.card-txt{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
/*And add this styles as classes on your HTML code as follows: */
<img class="card-svg" src="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 5zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/>
<img>
<h5 class="card-txt">Warning</h5>
/By the way i changed the svg into img you can try like that if this is what you want./
My Result
Just change first DIV style with text-align: center
Check the image from above make sure that way you want show
drop like if work for you.

Reduce height and width of 3 bars inside Font Awsome Hamburger

I want to make slim to 3 bars inside Hamburger. These 3 bars look fat when I apply "fa-2x".
Using code <i class="fa fa-bars"></i>
You can suscribe to pro licence to have acces to icon light style or you can use a custom svg.
Solid (free):
Light (pro):
Custom thin icon menu example
var faSplat = {
prefix: 'fac',
iconName: 'bars',
icon: [
448, 448, [],
null,
'M442 114H5a5 5 0 0 1-5-5V84a5 5 0 0 1 5-5h435a5 5 0 0 1 5 5v24a5 5 0 0 1-5 5zm0 160H5a5 5 0 0 1-5-5v-24a5 5 0 0 1 5-6h435a5 5 0 0 1 5 5v24a5 5 0 0 1-5 5zm0 160H5a5 5 0 0 1-5-5v-24a5 5 0 0 1 5-5h435a5 5 0 0 1 5 5v24a5 5 0 0 1-5 5z'
]
}
FontAwesome.library.add(faSplat)
<script src="https://use.fontawesome.com/releases/v5.0.9/js/all.js"></script>
<i class="fac fa-bars fa-2x"></i>
<br/>
<br/>
<div style="background-color : black; padding: 10px">
<i class="fac fa-bars fa-2x fa-inverse"></i>
</div>
More information about custom icons in fontawesome : https://github.com/mlwilkerson/fa-custom-icon-demo