I'm using bootstrap-icons, which does not yet have an "unsorted" icon like this:
So I'd like to stack two separate icons to achieve that effect:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.10.3/font/bootstrap-icons.css" rel="stylesheet">
<span class="d-inline-block position-relative" style="height: 1rem; width: 1rem;">
<i class="bi bi-caret-up position-absolute" style="font-size: 1rem; top: -5px;"></i>
<i class="bi bi-caret-down position-absolute" style="font-size: 1rem; top: 5px;"></i>
</span>
Run that code snippet, and open it in your browser's devtools - you'll notice the parent wrapper does not properly fit the contents. The parent <span> is smaller than the individual <i> icons. So when used in a table header cell (and other places too), it sometimes looks weird.
How could I fix this?
I have fiddled with your code and learned that:
the main span (class .unsorted) has to clip excess character spacing with overflow: hidden
line-height is already set to 1 by bootstrap for icons.
by default bootstrap icons have vertical-align: -0.125rem causing a slight shift up. I circumvented this by making the icons (<i>) display: grid, which also positions the characters nicely inside .unsorted.
A reasonable up/down offset for the characters seems to be 27.35%.
Additionally I introduced a few CSS custom properties to test various sizes of the combined character: sm, md, xl.
I know too little of bootstrap to be any use with that, so I created a vanilla CSS solution that seems to work with your bootstrap code.
snippet
/* * { outline: 1px dashed } /* for debugging */
body {
margin: 0;
min-height: 100vh;
display: grid; place-items: center;
}
.unsorted { background-color: rgb(128,128,128,.4) }
/********/
/* DEMO */
/********/
/* A few sizes to test variations */
.unsorted.sm { --button-size: 1em }
.unsorted.md { --button-size: 5em }
.unsorted.xl { --button-size: 9em }
.unsorted {
overflow: hidden; /* [MANDATORY] */
font-size: 1rem;
height: var(--button-size);
width : var(--button-size);
--icon-offset: 27.35%;
}
.unsorted i {
display: grid; /* centers the characters */
font-size: var(--button-size);
}
/* up/down offset, made to use positive numbers */
.bi.bi-caret-up { bottom: var(--icon-offset) }
.bi.bi-caret-down { top : var(--icon-offset) }
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.10.3/font/bootstrap-icons.css" rel="stylesheet">
<div>
<span class="d-inline-block position-relative unsorted xl">
<i class="bi bi-caret-up position-absolute" ></i>
<i class="bi bi-caret-down position-absolute"></i>
</span>
<span class="d-inline-block position-relative unsorted md">
<i class="bi bi-caret-up position-absolute" ></i>
<i class="bi bi-caret-down position-absolute"></i>
</span>
<span class="d-inline-block position-relative unsorted sm">
<i class="bi bi-caret-up position-absolute" ></i>
<i class="bi bi-caret-down position-absolute"></i>
</span>
</div>
Related
I have 3 elements that are displayed when hovering on the img element.
the problem is that when I hover over the icons, hovering over image disrupts and icons start flashing.(hovering happens back and forth between image and icon)
I know that I can add some class like this:
.dark-shield {
pointer-events: none;
}
to icons, and it fixes it but then I wont be able to apply the click event.
I appreciate if someone can help.
here is my code for display bellow:
.invisible {
visibility: hidden;
}
<div class="container transition-3d-hover ">
<a href="{% url "gallery-post" post.id %}">
<img id="{{ post.id }}" class="rounded "
src="{{ post.photo.url }}"
onmouseenter="f(this)"
onmouseleave="f(this)"
>
</a>
<i id="complain-icon-{{ post.id }}"
class=" fas fa-angry complain-box invisible icon-big dark-shield"></i>
<i id="fav-icon-{{ post.id }}"
class=" fa fa-hand-point-up like-box invisible icon-big "></i>
<i id="score-icon-{{ post.id }}"
class=" fas fa-heart fav-box invisible icon-big "></i>
</div>
<script>
function f(e) {
var complain = "#" + "complain-icon-" + e.id
var fav = "#" + "fav-icon-" + e.id
var score = "#" + "score-icon-" + e.id
$(complain).toggleClass('invisible')
$(fav).toggleClass('invisible')
$(score).toggleClass('invisible')
}
</script>
In your code, as you can see, the icons are not a part of the image. So, the icons become invisible when you hover them. After they are invisible, you hover over the image again, and the icon becomes visible. This keeps repeating. So, here is a code snippet that would solve this issue:
.img1 {
width: 100%;
height: 100%;
}
.icon {
color: white;
font-size: 30px;
position: absolute;
top: 40%;
left: 40%;
display: none;
}
#wrapper {
float: left;
width: 50%;
height: 30%;
cursor: pointer;
}
#wrapper:hover .icon {
display: block;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>
<body>
<div id="wrapper">
<img src="https://cdn.mos.cms.futurecdn.net/wtqqnkYDYi2ifsWZVW2MT4-1200-80.jpg" class="img1">
<i class="fas fa-angry icon"></i>
<i class="fa fa-hand-point-up icon" style="top: 20%;"></i>
<i class="fas fa-heart icon" style="left: 10%; top: 20%;"></i>
</div>
</body>
</html>
Please note: This code might not work in the snippet, but it would work if you create a new file with this code.
Code explained
As I have already explained, the icons are not a part of the image. So, when you hover them, they become invisible. However, in my code, I have inserted the images, as well as the icons inside one div. Now, whenever you hover the div, the icons are visible. Since the icons are a part of the same div, they would remain visible.
I have buttons which follow the following structure:
<button type="button" class="btn btn-dark btn-sm"(click)="doSomething()">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
They look like this:
I can change the height and width of the buttons and the inline icons will stay centered:
.btn.btn-dark.btn-sm {
height: 80px;
width: 200px;
}
But then when im making them smaller for mobile, all of the sudden, the inlined icons stop being centered after i fall below a certain width/height:
#media (max-width: 690px){
.btn.btn-dark.btn-sm {
width: 10px;
height: 20px;
}
}
Why do they stop being centered on small width/height? How would i fix it? I tried alligning them to the center etc, but didnt find a working solution yet.
It looks like the button may have some padding that interferes when too small. Try this snippet
.btn.btn-dark.btn-sm {
height: 20px;
width: 20px;
padding: 0;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<button type="button" class="btn btn-dark btn-sm" (click)="doSomething()">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
font awesome icon is getting cut off on the left hand side.
Snapshot
Below is my code
<div class="media-left">
<i class="fa fa-search fa-5x text-white"></i>
</div>
Css
.media-left{
display: table-cell;
vertical-align: top;
}
.text-white {
color: #fff;
}
.fa-5x {
font-size: 5em;
}
It might resolve your issue letter-spacing: 1px;
It might be because you have used 5x big font
you can use little search icon as well
<div class="media-left">
<i class="fa fa-search fa-4x text-white"></i>
</div>
It might resolve your issue
Since you're using display: table-cell; the icon itself isn't or atleast shouldn't be causing this. It could be another table-cell causing this or maybe something else. Since i can't say what is causing it because you haven't provided your other code i can only help you out with maybe another solution.
Since you want the icon to be around a single square how about using display: inline-block See the snippet below:
.media-left{
display: inline-block;
vertical-align: top;
background-color: black;
}
.text-white {
color: #fff;
}
.fa-5x {
font-size: 5em;
}
<head>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Fonts en Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- JQuery and Bootstrap.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<div class="media-left">
<i class="fa fa-search fa-5x text-white"></i>
</div>
Hope this helps!
There is the main restriction of font icons: it should be used only with specific font sizes for avoiding artifacts
https://fontawesome.com/how-to-use/on-the-web/styling/sizing-icons
As mentioned #Dmitro it might help if you are using not guaranteed font sizes or using dynamic scaling of your content
letter-spacing: 1px;
Also additionally next CSS adjustment might help too :
transform: rotate(0.03deg);
Maybe it's a bug, I'm not sure, but when using the mobile collapse menu, the icons and the text are not aligned (see images).
The reason is because of these CSS properties:
HTML:
.side-nav a {
color: #444;
display: block;
font-size: 1rem;
height: 64px;
line-height: 64px;
padding: 0 30px;
}
nav i.material-icons {
display: block;
font-size: 2rem;
height: 56px;
line-height: 56px;
}
<ul style="transform: translateX(0px);" class="side-nav" id="mobile-menu">
<img src="images/costum_logos/logo3.png" class="custom-logo">
<div class="divider"></div>
<a href="index.php" class="waves-effect waves-light">Albums
<i class="material-icons left notranslate">collections</i>
</a>
<a href="?page=settings" class="waves-effect waves-light">Settings
<i class="material-icons left notranslate">settings</i></a>
<a class="waves-effect waves-light red-text text-lighten-1" href="index.php?logout">Logout
<i class="material-icons left notranslate">power_settings_new</i>
</a>
</ul>
Of course, the interesting bits are the line-height and height properties on both the anchor tag, and the icon tag. They are not equal. If I override either one of them, to be exactly like the other - they are perfectly aligned.
My question is: Am I doing something wrong? I can easily get around it, but I want to have a good practice with materialize CSS. Don't wanna hack around and break their conventions.
Thanks in advance!
I am trying to POST to a server using <button type="submit"> save </button> but I need to style the button to look a certain way using css.
Here is what im trying to accomplish:
But this is what i get:
I need to style the button element to look like the correct image and remove the default button styles.
CSS
.inner-button
{
color: #008db8;
}
.inner-button:hover
{
color: #ad9961;
cursor: pointer;
text-decoration: none;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<button class="inner-button" type="submit" >
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x img-responsive"></i>
<i class="fa fa-floppy-o fa-stack-1x fa-inverse img-responsive"></i>
</span><br />
<b>Save</b>
</button>
You just have to remove the default CSS styling.
.inner-button {
background: none;
border: none;
margin: 0;
padding: 0;
}