Iconfont display and hover - html

I have five links at the bottom of my page. Next to each link is an <i></i> with a Font Awesome heart icon class attribute. I am trying to have the icons not be displayed until the links are hovered over. I have a few questions/issues:
1) Display: hidden would not work on the icons. Is that normal? Visibility: hidden did make them disappear, but as with the visibility property, it did not remove them from the document flow.
2) I could not get the icons to reappear when hovering over the links. The only way I could get them to reappear on hover is by using:
.main-nav__link-container:hover .main-nav__link__icon {
visibility: initial;
}
The problem with the above CSS is that the entire div being hovered over will show the heart, which means I can hover over an area that is not a link (the area where the icon is), and the icon will pop up, but not be clickable. I only want the icon to show up when the actual link is hovered over. Any idea how to do this?
Codepen with full html/css (code associated with question is at the bottom of both the html and css). I have commented out visibility: hidden for the icons so that you can see where they are:
https://codepen.io/pmc222/pen/jvJRyg
HTML
/* Styles link flex items */
.main-nav__link {
text-decoration: none;
color: rgb(0, 0, 0);
font-family: "Montserrat", sans-serif;
font-size: 0.9rem;
letter-spacing: 0.2em;
padding-bottom: 5px;
text-transform: uppercase;
}
/* Styles icon font next to nav links */
.main-nav__link__icon {
display: none;
font-size: 0.9em;
color: rgba(0, 0, 0, 0.6);
margin-right: 3px;
visibility: hidden;
}
*unsure what selector to put here* .main-nav__link__icon {
visibility: initial;
}
/* Adds underline to links on mouse over */
.main-nav__link:hover {
border-bottom: 2px solid rgb(42, 136, 212);
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"/>
<footer id="main-footer">
<nav id="main-nav">
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="wedding-party.html">Wedding Party</a>
</div>
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="venue-information.html">Venue Information</a>
</div>
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="accommodations.html">Accommodations</a>
</div>
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="event-information.html">Event Information</a>
</div>
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="registry.html">Registry</a>
</div>
</nav>
</footer>

From looking at the code, the issue is that you are trying to display and hide the icons using the link class (which comes after the fa icon), whereas if you targeted the container which holds both the heart and the link, the show/hide would be successful.
If you set the visibility to hidden in your __link__icon class and then display it on hover like so:
.main-nav__link-container:hover .main-nav__link__icon {
visibility:visible;
}
it should display.
Fiddle

You should use display:none and display:block CSS rules instead display:hidden.
Some like this:
.main-nav__link {
display:none;
}
.main-nav__link: hover {
display:block;
}

Related

icon changing width when near inline element

I have a list of users, with two inline elements: a "contact me" button ('a' element with a fontawesome icon) and a tag showing the type of user (span element).
Not all users have a tag, and whenever there is a tag, the 'a' element is giving to the icon more width than it needs. This is how it looks like:
As you can see, the bottom one fits correctly, while the blue space of the top one is bigger on the right. They have the exact same classes and attributes (this is generated from a loop, so it's the same code).
This is the HTML code for the link+span:
.item-title {
margin-bottom: 10px;
}
.item-btn-contact {
margin-left: 10px;
padding: 3px 10px;
border-radius: 5px;
background-color: #1b95e0;
font-size: 80%;
color: #fff;
text-decoration: none;
}
.item-type-tag {
margin-left: 10px;
padding: 3px 5px;
border-radius: 5px;
background-color: #dedede;
font-weight: bold;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet"/>
<div class="item-title">
xxxx
<a href="" class="item-btn-contact" title="Contattami">
<i class="fas fa-envelope"></i>
</a>
<span class="item-type-tag">Allenatore</span>
</div>
<div class="item-title">
xxxx
<a href="" class="item-btn-contact" title="Contattami">
<i class="fas fa-envelope"></i>
</a>
</div>
I tried checking if there was any difference in the cumputed styles of the two elements through javascript (maybe there was a ":last-child" selector somewhere), but their maps looks exactly the same (checked using getComputedStyle on both elements).
Whenever I change the span element display property to block, flex, or other not-inline options, the other element resize itself in the correct way.
The only option I found is to change the icon width to .8em (currently 1em), and then add a last-child selector to resize it correctly to 1em when there is no span on the right, but it's not a real solution...
Could anyone help me figure out why, or at least how to fix it?
Set the display on item-btn-contact to inline-block. Seems like the default display of a (inline) is messing with the sizing.
.item-title {
margin-bottom: 10px;
}
.item-btn-contact {
margin-left: 10px;
padding: 3px 10px;
border-radius: 5px;
background-color: #1b95e0;
font-size: 80%;
color: #fff;
text-decoration: none;
display: inline-block;
}
.item-type-tag {
margin-left: 10px;
padding: 3px 5px;
border-radius: 5px;
background-color: #dedede;
font-weight: bold;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet"/>
<div class="item-title">
xxxx
<a href="" class="item-btn-contact" title="Contattami">
<i class="fas fa-envelope"></i>
</a>
<span class="item-type-tag">Allenatore</span>
</div>
<div class="item-title">
xxxx
<a href="" class="item-btn-contact" title="Contattami">
<i class="fas fa-envelope"></i>
</a>
</div>

How can I do a Transparent and Fixed Footer with Social Media Icons?

I'm trying to develop a website for my band, but I cannot solve this problem. So, to put you in context, I have a footer that I want to be fixed all the time in the website. So If you want to scroll down the page, even in the top of the page you will be able to see the footer (the footer will be social media icons).
So my main problem now is that I want to have 3 different parts in my page:
1. The nav bar that will be displayed at the top of the page (if it is fixed as well as the footer, would be excellent)
2. My main/head part that will be displayed, for example, images from a gallery.
3. The footer part that I want to be fixed and will be displayed social media icons (in total 4: IG, YT, Spotify, Apple Music).
So as you can see in the image
https://imgur.com/AKFgfga
The main problem is that the footer in the bottom is collapsing the images I want to display in this page of the website. So I want to have this footer always fixed in order to not collapse the images. Does anyone know how to code that? I'd totally appreciate :D
This is the coding I'm using for the footer section:
footer {
position: fixed;
bottom: 0;
width: 99%;
text-align: center;
margin-bottom: 30px
}
.media {
display: inline-block;
width: 60px;
height: 90px;
margin: 10px;
}
.media i {
color: white;
font-size: 50px;
}
.media:hover i {
opacity: 0.7;
}
.grow {
transition: all .2s ease-in-out;
}
.grow:hover {
transform: scale(1.3);
}
<footer>
<div class="fa">
<a class="media" href="https://www.instagram.com/massaviu/" target="_blank">
<i class="fab fa-instagram grow" style="color: #E1306C"></i>
</a>
<a class="media" href="https://www.youtube.com/channel/UCh1_-QpgzIdG-3QfCMfZi6w" target="_blank">
<i class="fab fa-youtube grow" style="color: #FF0000"></i>
</a>
<a class="media" href="https://open.spotify.com/artist/0du3FPmKtQ8vfsmGYVzdFY" target="_blank">
<i class="fab fa-spotify grow" style="color: #1DB954"></i>
</a>
<a class="media" href="https://music.apple.com/us/artist/massaviu/1378812000" target="_blank">
<i class="fab fa-apple grow" style="color: #A3AAAE"></i>
</a>
</div>
</footer>

Disabling color on font awesome icon

I just added a href tag to my font awesome icon, which alters its color like so:
Is there a way to remove this link color?
<i class="fa fa-facebook"></i>
In your CSS:
.fa-facebook {
color: black; /* or any other color */
}
You can't "remove" the color, but you can change the color to something else.
Simply use CSS with a class
a.black{color: #000 !important}
Or on all atags
a{color: #000 !important}
Or directly on the tag
<i class="fa fa-facebook"></i>
I'm adding the important tag, to ensure it stays black when being clicked or active.
You can change the color for all .fa icons inside anchor tags
a .fa {
color: black;
}
Demo in Stack Snippets
a .fa {
color: black;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<i class="fa fa-facebook"></i>

Is there any way to inherit background-color from a parent element, as foreground color of child element?

I am using font awesome to make some icons. I've most recently started playing with stacked icons. I want to achieve an effect, similar to the top icon being a cut-out of the base icon. Meaning that the background color of their parent should be visible through the "hole" in the base icon.
Initially, I tried to set the top Icon to be transparent, but that only revealed the full base icon, with no stacked icon result whatsoever.
Is there a way to achieve this, maybe by inheriting the parent element's background color, and setting it as the foreground color of the top Icon?
HTML:
<div class="square">
<span class="fa-stack ">
<i class="fa fa-file fa-stack-2x fa-inverse"></i>
<i class="fa fa-refresh fa-stack-1x " style="margin-top: 6px; "></i>
</span>
</div>
CSS:
.square{
background-color: rgb(51, 179, 77);
width: 32px;
height: 32px;
}
And fiddle, (where I am trying to make the black "refresh"-icon the same color as the background base) http://jsfiddle.net/cat9zxzt/
EDIT:
I know I could just add the color to the icon element manually, but what I would like, is a generic solution that would work with any background color that I might happen to put this stacked icon on top of.
You can (sort of) by setting the text color and using currentColor for the background.
The currentColor keyword represents the calculated value of the element's color property. It allows to make the color properties inherited by properties or child's element properties that do not inherit it by default.
.square {
color: rgb(51, 179, 77); /* text color */
background-color: currentColor; /* equals current text color */
width: 32px;
height: 32px;
}
JSfiddle Demo
Just add another class to the refresh icon as seen in this Fiddle
HTML
<div class="square">
<span class="fa-stack ">
<i class="fa fa-file fa-stack-2x fa-inverse"></i>
<i class="fa fa-refresh fa-stack-1x green-color" style="margin-top: 6px; "> </i>
</span>
</div>
CSS
.square{
background-color: rgb(51, 179, 77);
width: 32px;
height: 32px;
}
.green-color{
color: rgb(51, 179, 77);
}

Changing the color of an icon from FontAwesome?

I am using BigCommerce, and have this for my code:
.icon-cart {
color: #4ca3c0 !important;
}
.icon-cart a{
color: #4ca3c0 !important;
}
and it won't change the color of the icon. Any help?
http://glymed-plus.mybigcommerce.com/
The fontAwesome installation is messed up.
The reason color CSS attribute won't change the color of the shopping cart is because the shopping cart is being rendered by a sprite:
.icon {
display: inline-block;
width: 16px;
height: 14px;
background: url("http://cdn3.bigcommerce.com/r-13587bfb690318eb6b3c052034841f2aff994eb4/themes/ClassicNext/images/icon_sprite.png") no-repeat 0 -27px;
}
(the background is loading an image, instead of the icon).
See http://fortawesome.github.io/Font-Awesome/get-started/
You might not have copied the other folders in the installation.
If you remove the background, install the other dirs, and keep your HTML, it should work.
EDIT: You were right, fontAwesome is correctly installed.
Now change the <i> element:
<i class="fa fa-shopping-cart" title="View Cart"> </i>
You can set the size and position to better the display, but the fa and fa-shopping-cart classes must be set for showing the shopping cart icon.
Your icon is not css made, it is a png image that is loaded as the icon's background.
you cannot just 'change' its color, you need to adjust it using CSS Filters
in your case, you can apply invert on the <i> element:
-webkit-filter: invert(100%);
to change it from gray to white.
body {
background: black;
}
.icon {
display: inline-block;
width: 16px;
height: 14px;
background: url("http://cdn3.bigcommerce.com/r-13587bfb690318eb6b3c052034841f2aff994eb4/themes/ClassicNext/images/icon_sprite.png") no-repeat 0 -27px;
-webkit-filter: invert(100%);
}
.icon:hover {
-webkit-filter: invert(0%);
}
<i class="icon icon-cart" title="View Cart" style="
color: red;
"> </i>
First Remove !important
.icon-cart {
color: #4ca3c0;
}
.icon-cart a{
color: #4ca3c0;
}
now here is how you markup looks like
<a href="" title="View Cart">
<i class="icon icon-cart" title="View Cart"> </i>
<span></span>
</a>
.icon-cart is i and has no child.
So this is not valid:
.icon-cart a{
color: #4ca3c0;
}