need css trick to solve this issue - css

Hi guys so I'm working on a website with an orange background. I'm using white social icons from the Font Awesome library.
Here is the result of my work
CSS
#import url('http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
#import url('http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font- awesome.min.css');
body {
margin: 10px;
background:#da4a10;
}
#social:hover {
-webkit-transform:scale(1.1);
-moz-transform:scale(1.1);
-o-transform:scale(1.1);
}
#social {
-webkit-transform:scale(0.8);
/* Browser Variations: */
-moz-transform:scale(0.8);
-o-transform:scale(0.8);
-webkit-transition-duration: 0.5s;
-moz-transition-duration: 0.5s;
-o-transition-duration: 0.5s;
}
.fa-3x{
color: white;
}
.social-fb:hover {
color: #3B5998;
}
.social-tw:hover {
color: #4099FF;
}
.social-gp:hover {
color: #d34836;
}
.social-em:hover {
color: #f39c12;
}
HTML
<div id="row">
<div class="col-xs-2 col-sm-8 col-lg-2 col-md-6">
<a href="#">
<i id="social" class="fa fa-facebook-square fa-3x social-fb"></i>
</a>
</div>
<div class="col-xs-2 col-sm-8 col-lg-2 col-md-6">
<a href="#">
<i id="social" class="fa fa-twitter-square fa-3x social-tw"></i>
</a>
</div>
<div class="col-xs-2 col-sm-8 col-lg-2 col-md-6">
<a href="#">
<i id="social" class="fa fa-google-plus-square fa-3x social-gp"></i>
</a>
</div>
<div class="col-xs-2 col-sm-8 col-lg-2 col-md-6 ">
<a href="#">
<i id="social" class="fa fa-envelope-square fa-3x social-em"></i>
</a>
</div>
</div>
http://jsfiddle.net/DTcHh/5582/
I need a solution because when I hover over the social icons, the look of it is not so nice. I tried adding a white background to the icons but it's still not functioning properly.

Since you are using Font Awesome, there is an icon available called: fa-square. This has the exact shape of the square social media icons. Also, Font Awesome has the opportunity to stack icons. If you stack a fa-square under a fa-twitter-square e.g. and make fa-square white, it will solve your problem.
HTML
<div id="row">
<div class="col-xs-2 col-sm-8 col-lg-2 col-md-6">
<a href="#">
<span class="fa-stack fa-2x social social-fb">
<i class="fa fa-square fa-stack-1x white-bg"></i>
<i class="fa fa-facebook-square fa-stack-2x "></i>
</span>
</a>
</div>
<div class="col-xs-2 col-sm-8 col-lg-2 col-md-6">
<a href="#">
<span class="fa-stack fa-2x social social-tw">
<i class="fa fa-square fa-stack-1x white-bg"></i>
<i class="fa fa-twitter-square fa-stack-2x "></i>
</span>
</a>
</div>
<div class="col-xs-2 col-sm-8 col-lg-2 col-md-6">
<a href="#">
<span class="fa-stack fa-2x social social-gp">
<i class="fa fa-square fa-stack-1x white-bg"></i>
<i class="fa fa-google-plus-square fa-stack-2x "></i>
</span>
</a>
</div>
<div class="col-xs-2 col-sm-8 col-lg-2 col-md-6 ">
<a href="#">
<span class="fa-stack fa-2x social social-em">
<i class="fa fa-square fa-stack-1x white-bg"></i>
<i class="fa fa-envelope-square fa-stack-2x "></i>
</span>
</a>
</div>
</div>
CSS
/* Optional theme */
#import url('http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
#import url('http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');
body {
background: #DA4A10;
margin: 10px;
}
.social {
color: #F9F9F9;
transition: 0.5s;
-moz-transition: 0.5s;
-ms-transition: 0.5s;
-o-transition: 0.5s;
-webkit-transition: 0.5s;
}
/* Definition of the white background */
.white-bg {
color: white;
font-size: 54px;
opacity: 0;
transition: 0.5s;
-moz-transition: 0.5s;
-ms-transition: 0.5s;
-o-transition: 0.5s;
-webkit-transition: 0.5s;
}
.social-fb:hover{
color: #3B5998;
}
.social-tw:hover {
color: #4099FF;
}
.social-gp:hover {
color: #d34836;
}
.social-em:hover {
color: #f39c12;
}
/* Show the white background on hover */
.social-fb:hover .white-bg, .social-tw:hover .white-bg,
.social-gp:hover .white-bg, .social-em:hover .white-bg {
opacity: 1;
}
Solution in action: http://jsfiddle.net/DTcHh/6084/

Related

Target specific element in CSS?

Happy morning everyone,
I don't manage to target .fa-caret-down or up (inside a i and span) with the a[aria-expanded=true] which share the same div parent, do you know how to do it ?
I try with the selector ~, or to move the fa-caret-up (and succeed), but you are really good here, so here a light version of the code if you can find a solution.
Thanks !
<style>
a[aria-expanded="true"] .fa-caret-up {
display: none;
}
a[aria-expanded="false"] .fa-caret-down {
display: none;
}
</style>
<div class="container-fluid d-flex justify-content-center">
<div class="row">
<div class="col-lg-4 col-md-6 col-12 pb-5">
<h4 class="text-center">eCampus</h4>
<div class="d-flex justify-content-between align-items-center">
<a href="#" data-toggle="collapse" data-target="#footer_ups" aria-expanded="false" aria-controls="footer_ups">
<span class="flex-grow-1 mr-5"><i class="fa fa-chevron-right pr-2"></i>Université Paris-Saclay</span>
</a>
<span class="badge badge-primary badge-pill">7 <i class="fa fa-caret-down"></i><i class="fa fa-caret-up"></i></span>
</div>
<div id="footer_ups" class="collapse pl-3" aria-labelledby="Établissements de l'Université Paris-Saclay">
<ul class="list-unstyled">
<li><i class="fa fa-angle-right pr-2"></i> UPSaclay</li>
<li><i class="fa fa-angle-right pr-2"></i> UEVE</li>
<li><i class="fa fa-angle-right pr-2"></i> UVSQ</li>
<li><i class="fa fa-angle-right pr-2"></i> Centrale Supéle</li>
<li><i class="fa fa-angle-right pr-2"></i> École Normale Supérieure</li>
<li><i class="fa fa-angle-right pr-2"></i> Institut d'Optique</li>
<li><i class="fa fa-angle-right pr-2"></i> AgroParisTech</li>
</ul>
</div>
<div class="d-flex justify-content-between align-items-center">
<a href="#" class="text-nowrap pr-5" data-toggle="collapse" data-target="#footer_ipp" aria-expanded="false" aria-controls="footer_ipp">
<span><i class="fa fa-chevron-right pr-2"></i>Institut Polytechnique de Paris</span>
</a>
<span class="badge badge-primary badge-pill">4 <i class="footer_ipp_glyph fa fa-caret-down"></i></span>
</div>
<div id="footer_ipp" class="collapse pl-3" aria-labelledby="Établissements de l'Institut Polytechnique de Paris">
<ul class="list-unstyled">
<li><i class="fa fa-angle-right pr-2"></i> ENSTA</li>
<li><i class="fa fa-angle-right pr-2"></i> INSTN</li>
<li><i class="fa fa-angle-right pr-2"></i> Télécom Paris</li>
<li><i class="fa fa-angle-right pr-2"></i> Télécom Evolution</li>
</ul>
</div>
<br />
<i class="fa fa-chevron-right pr-2"></i>Alliance EUGLOH pour les étudiants
</div>
<div class="col-lg-4 col-md-6 col-12 pb-4">
<h4 class="text-center">Aide et Informations légales</h4>
<ul class="list-unstyled">
<li><i class="fa fa-chevron-right pr-2"></i>Problèmes de connexion</li>
<li><i class="fa fa-chevron-right pr-2"></i>Aide et accessibilité</li>
<li> <li>
<li><i class="fa fa-chevron-right pr-2"></i>Conditions générales d'utilisation</li>
<li><i class="fa fa-chevron-right pr-2"></i>Crédits</li>
<li><i class="fa fa-chevron-right pr-2"></i>Mentions légales</li>
<li><i class="fa fa-chevron-right pr-2"></i>Politique de confidentialité</li>
<li> <li>
<li><i class="fa fa-chevron-right pr-2"></i>Obtenir l'app mobile</li>
</ul>
</div>
<div class="col-lg-4 col-md-12 text-center">
<h4 class="text-center">Suivez-nous</h4>
<i class="fa fa-facebook-square fa-3x mr-3"></i>
<i class="fa fa-twitter-square fa-3x mr-3"></i>
<i class="fa fa-linkedin-square fa-3x mr-3"></i>
<i class="fa fa-instagram fa-3x"></i>
</div>
</div>
</div>
If you want to make caret up and down animation you can use little JS
const caret = document.querySelector('.caret');
caret.addEventListener('click', (e) => {
e.preventDefault();
caret.classList.toggle('collapsed');
if (caret.classList.contains('collapsed')) {
caret.setAttribute("aria-expanded", "true");
} else {
caret.setAttribute("aria-expanded", "false");
}
console.log(caret.getAttribute('aria-expanded'))
});
* {
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: grid;
place-items: center;
}
.caret {
width: 70px;
height: 70px;
display: grid;
place-items: center;
border-radius: 0.25rem;
border: 1px solid #e5e5e5;
}
.caret svg {
width: 64px;
height: 64px;
transition: transform 250ms ease;
}
.caret.collapsed svg {
transform: rotate(180deg);
}
<a href="#" class="caret" aria-expanded="false">
<svg width="24" height="24" viewBox="0 0 24 24">
<path d="m11.998 17 7-8h-14z"></path>
</svg>
</a>
You have to select the sibling first and then the i tags if you want to use the general sibling selector (~). For example:
a[aria-expanded="true"] ~ span .fa-caret-up {...}
Working example:
a[aria-expanded=true] ~ span .fa-caret-up {
display: none;
}
a[aria-expanded=false] ~ span .fa-caret-down {
display: none;
}
<script src="https://kit.fontawesome.com/79efab5353.js" crossorigin="anonymous"></script>
<div class="container-fluid d-flex justify-content-center">
<div class="row">
<div class="col-lg-4 col-md-6 col-12 pb-5">
<h4 class="text-center">Moodle</h4>
<div class="d-flex justify-content-between align-items-center mr-5">
<a href="#" data-toggle="collapse" data-target="#footer_ups" aria-expanded="false" aria-controls="footer_ups">
<span class="flex-grow-1"><i class="fa fa-chevron-right pr-2"></i>Uni</span>
</a>
<span class="badge badge-primary badge-pill">7 <i class="fa fa-caret-down"></i><i class="fa fa-caret-up"></i></span>
</div>
<div id="footer_ups" class="collapse pl-3" aria-labelledby="Établissements">
<ul class="list-unstyled">
<li><i class="fa fa-angle-right pr-2"></i> Website</li>
</ul>
</div>
</div>
</div>
</div>

How to align icon and text [duplicate]

<div class="col-md-4">
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x blue"></i>
<i class="fa fa-wifi fa-stack-1x white"></i>
</span>
<h4 class="blue">Free wifi</h4>
</div>
How can I display h4 element on the right of the icon and vertically aligned? Should I float left the span?
One of the ways would be to use inline-block display and middle align it - see demo below:
.wrapper > * {
display: inline-block;
vertical-align: middle;
}
.blue {
color: blue;
}
.white {
color: white;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="col-md-4 wrapper">
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x blue"></i>
<i class="fa fa-wifi fa-stack-1x white"></i>
</span>
<h4 class="blue">Free wifi</h4>
</div>
Use CSS Flexbox. Make a parent <div> that wraps icon and text into it (in my case its icon-holder) and make it a flexbox container using display: flex.
Have a look at the snippet below:
.icon-holder {
display: flex; /* Flex Container */
align-items: center; /* Vertically Align Content */
}
.blue {
color: #33b5e5;
}
span {
color: #fff;
}
h4 {
padding-left: 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="col-md-4">
<div class="icon-holder">
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x blue"></i>
<i class="fa fa-wifi fa-stack-1x white"></i>
</span>
<h4 class="blue">Free wifi</h4>
</div>
</div>
Hope this helps!
You can use display: flex and can do something like below :
.col-md-4 {
display: flex;
align-items: center;
}
.blue {
color: blue
}
.white {
color: white;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<div class="col-md-4 wrapper">
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x blue"></i>
<i class="fa fa-wifi fa-stack-1x white"></i>
</span>
<h4 class="blue">Free wifi</h4>
</div>

How to color half icon using ReactJS and Font-awesome?

I want to display some icons from font-awesome for a rating system.
At this point I just want to display the result but I didn't find how to colour only half of the star icon.
For instance, if the rate is 3.5 I would display 3 yellow stars, 1 half star in yellow and the rest in grey.
Is there a way to do it with reactjs Font-aweosome component (
import FontAwesome from 'react-fontawesome';)?
It is not possible to color half of the fontawesome icons but you can try using this technique.
.header_star{
float: left;
margin-left: 10px;
position: relative;
}
.header_star .fa.fa-star{
font-size: 20px;
}
.header_star:hover {
text-decoration: none;
}
.header_star .star_hover .fa.fa-star {
color: #ffd200;
}
.star_hover {
bottom: 0;
left: 0;
overflow: hidden;
position: absolute;
top: 0;
white-space: nowrap;
width: 0;
transition: all 0.3s linear 0s;
}
.header_star:hover .star_hover {
width: 92%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<div class="header_star">
<a href="#" class="header_star">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<div class="star_hover">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</div>
</a>
</div>

Position animated icons and remove overlapping using CSS

I am trying to position the icons to the right and the tags to the center.
My website is using BootStrap and Font-Awesome. Below is the HTML:
<div class="row">
<div class="col-lg-12" style="text-align: center">
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Health</span>
</a>
<span> </span>
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Fitness</span>
</a>
<span> </span>
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Safety</span>
</a>
<span> </span>
<i class="fa fa-heart faa-pulse animated" style="float:right;"></i>
<i class="fa fa-star faa-pulse animated" style="float:right;"></i>
<i class="fa fa-smile-o faa-pulse animated" style="float:right;"></i>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h1 class="post-header" style="text-align: center">This is the header</h1>
</div>
</div>
CSS:
#keyframes pulse {
0% {
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
50% {
-webkit-transform: scale(0.8);
-ms-transform: scale(0.8);
transform: scale(0.8);
}
100% {
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
}
.faa-pulse.animated,
.faa-pulse.animated-hover:hover,
.faa-parent.animated-hover:hover > .faa-pulse {
-webkit-animation: pulse 2s linear infinite !important;
animation: pulse 2s linear infinite !important;
font-size:1.8em;
}
.fa-heart {
color: red !important;
}
.fa-star {
color: gold !important;
}
.fa-smile-o {
color: deeppink !important;
}
The problem is my icons are overlapping with each other during animation and the tags are not aligned to the center. Also,there is very little space between the icons. How can I solve this problem?
Here is the demo
Try this:
Re-formated HTML:
<div class="row">
<div class="col-lg-12 text-center">
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Health</span>
</a>
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Fitness</span>
</a>
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Safety</span>
</a>
<span class="animated-icons">
<i class="fa fa-heart faa-pulse animated"></i>
<i class="fa fa-star faa-pulse animated" ></i>
<i class="fa fa-smile-o faa-pulse animated" ></i>
</span>
</div>
</div>
CSS:
.animated-icons {
position: absolute;
right: 15px;
}
There are 2 ways to do this,
from user guide example http://fontawesome.io/examples/
Use fa-fw to set icons at a fixed width. Great to use when different icon widths throw off alignment. Especially useful in things like nav lists & list groups.
<div class="row">
<!-- edited (1) -->
<div class="col-lg-12" style="text-align: center;position: relative;">
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Health</span>
</a>
<span> </span>
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Fitness</span>
</a>
<span> </span>
<a href="#" style="text-decoration: none;">
<span style="background-color: #171717; color: #FFF; padding: 2px">Safety</span>
</a>
<!-- edited (2) -->
<div style="position: absolute;top: 0;right: 0;">
<i class="fa fa-fw fa-heart faa-pulse animated" ></i>
<i class="fa fa-fw fa-star faa-pulse animated" ></i>
<i class="fa fa-fw fa-smile-o faa-pulse animated" ></i>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h1 class="post-header" style="text-align: center">This is the header</h1>
</div>
</div>
or u could change css
.faa-pulse{
margin:3px;
}
see this https://jsfiddle.net/jayakrishnancn/73Lfxnpg/3/
Try Adding margin to the font Awesome Icons
i.fa
{
margin:4px;
}
Hope this helps.. :D

Vertical placement of Fontawesome icons

I am trying to align vertical blocks containing icons and some text. Everything works as expected until the text is too large for the block.
.big-icons .big-icon {
font-size: 42px;
margin-bottom: 10px;
text-align: center;
line-height: 3.2em;
}
.big-icons .big-icon a .text {
font-size: 18px;
position: relative;
text-transform: uppercase;
top: 3em;
white-space: nowrap;
}
.big-icons .big-icon a {
font-weight: 300;
text-decoration: none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="big-icons">
<span class="big-icon">
<a target="_blank" href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-magic fa-stack-1x fa-inverse"></i>
<span class="text">Short title</span>
</span>
</a>
</span>
<div class="visible-xs divider"></div>
<span class="big-icon">
<a target="_blank" href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-area-chart fa-stack-1x fa-inverse"></i>
<span class="text">Very long long text</span>
</span>
</a>
</span>
<div class="visible-xs divider"></div>
<span class="big-icon">
<a target="_blank" href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-dropbox fa-stack-1x fa-inverse"></i>
<span class="text">Title</span>
</span>
</a>
</span>
<div class="visible-xs divider"></div>
</div>
How do i make the link containing text "Very long long text" to not intersect with text "Title" on the right ?
Seems like the fa-stack-1x class gives the icon position:absolute and thats why its not being centered properly. I would try to use fa just to render the icon in certain size and do everything else in my own css. The circle with border radius, own position etc.

Resources