Make Font Awesome icons in a circle? - css

I am using font awesome on some project but I have some things that I want to do with font awesome icons, I can easily call an icon like this:
<i class="fa fa-lock"></i>
Is it possible to all icon always be in round circle with border? Something like this, I have a picture:
Using
i {
background-color: white;
border-radius: 50%;
border: 1px solid grey;
padding: 10px;
}
Will do the effect, but the problem is that icons are always bigger that the text or element beside, any solutions?

With Font Awesome you can easily use stacked icons like this:
UPDATE: Font Awesome v6.2.1
<span class="fa-stack fa-2x">
<i class="fa-thin fa-circle fa-stack-2x"></i>
<i class="fa-solid fa-lock fa-stack-1x fa-inverse"></i>
</span>
UPDATE: Font Awesome v5.15.4
<span class="fa-stack fa-2x">
<i class="fal fa-circle fa-stack-2x"></i>
<i class="fas fa-lock fa-stack-1x fa-inverse"></i>
</span>
refer Font Awesome Stacked Icons
Update:-
Fiddle for stacked icons

i.fa {
display: inline-block;
border-radius: 60px;
box-shadow: 0 0 2px #888;
padding: 0.5em 0.6em;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<i class="fa fa-wrench"></i>
JsFiddle of old answer: http://fiddle.jshell.net/4LqeN/

You don't need css or html tricks for it.
Font Awesome has built in class for it - fa-circle To stack multiple icons together you can use fa-stack class on the parent div
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-flag fa-stack-1x fa-inverse"></i>
</span>
//And we have now facebook icon inside circle:)

Font icon in a circle using em as the base measurement
if you use ems for the measurements, including line-height, font-size and border-radius, with text-align: center it makes things pretty solid:
#info i {
font-size: 1.6em;
width: 1.6em;
text-align: center;
line-height: 1.6em;
background: #666;
color: #fff;
border-radius: 0.8em; /* or 50% width & line-height */
}

Update: Rather use flex.
If you want precision this is the way to go.
Fiddle. Go Play -> http://jsfiddle.net/atilkan/zxjcrhga/
Here is the HTML
<div class="sosial-links">
<i class="fa fa-facebook fa-lg"></i>
<i class="fa fa-twitter fa-lg"></i>
<i class="fa fa-google-plus fa-lg"></i>
<i class="fa fa-pinterest fa-lg"></i>
</div>
Here is the CSS
.sosial-links a{
display: block;
float: left;
width: 36px;
height: 36px;
border: 2px solid #909090;
border-radius: 20px;
margin-right: 7px; /*space between*/
}
.sosial-links a i{
padding: 12px 11px;
font-size: 20px;
color: #909090;
}
NOTE: Don't use this anymore. Use flexbox.

UPDATE:
Upon learning flex recently, there is a cleaner way (no tables and less css). Set the wrapper as display: flex; and to center it's children give it the properties align-items: center; for (vertical) and justify-content: center; (horizontal) centering.
See this updated JS Fiddle
Strange that nobody suggested this before.. I always use tables to do this.
Simply make a wrapper have display: table and center stuff inside it with text-align: center for horizontal and vertical-align: middle for vertical alignment.
<div class='wrapper'>
<i class='icon fa fa-bars'></i>
</div>
and some sass like this
.wrapper{
display: table;
i{
display: table-cell;
vertical-align: middle;
text-align: center;
}
}
or see this JS Fiddle

You can also do this. I wanted to add a circle around my icomoon icons. Here is the code.
span {
font-size: 54px;
border-radius: 50%;
border: 10px solid rgb(205, 209, 215);
padding: 30px;
}

This is the approach you don't need to use padding, just set the height and width for the a and let the flex handle with margin: 0 auto.
.social-links a{
text-align:center;
float: left;
width: 36px;
height: 36px;
border: 2px solid #909090;
border-radius: 100%;
margin-right: 7px; /*space between*/
display: flex;
align-items: flex-start;
transition: all 0.4s;
-webkit-transition: all 0.4s;
}
.social-links a i{
font-size: 20px;
align-self:center;
color: #909090;
transition: all 0.4s;
-webkit-transition: all 0.4s;
margin: 0 auto;
}
.social-links a i::before{
display:inline-block;
text-decoration:none;
}
.social-links a:hover{
background: rgba(0,0,0,0.2);
}
.social-links a:hover i{
color:#fff;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="social-links">
<i class="fa fa-facebook fa-lg"></i>
<i class="fa fa-twitter fa-lg"></i>
<i class="fa fa-google-plus fa-lg"></i>
<i class="fa fa-pinterest fa-lg"></i>
</div>

The below example didnt quite work for me,this is the version that i made work!
HTML:
<div class="social-links">
<i class="fa fa-facebook fa-lg"></i>
<i class="fa fa-twitter fa-lg"></i>
<i class="fa fa-google-plus fa-lg"></i>
<i class="fa fa-pinterest fa-lg"></i>
</div>
CSS:
.social-links {
text-align:center;
}
.social-links a{
display: inline-block;
width:50px;
height: 50px;
border: 2px solid #909090;
border-radius: 50px;
margin-right: 15px;
}
.social-links a i{
padding: 18px 11px;
font-size: 20px;
color: #909090;
}

try this
HTML:
<div class="icon-2x-circle"><i class="fa fa-check fa-2x"></i></div>
CSS:
i {
width: 30px;
height: 30px;
}
.icon-2x-circle {
text-align: center;
padding: 3px;
display: inline-block;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
-moz-box-shadow: 0px 0px 2px #888;
-webkit-box-shadow: 0px 0px 2px #888;
box-shadow: 0px 0px 2px #888;
}

Font Awesome icons are inserted as a :before. Therefore you can style either your i or a like so:
.i {
background: #fff;
border-radius: 50%;
display: inline-block;
height: 20px;
width: 20px;
}
<i class="fa fa-facebook fa-lg"></i>

You can simply get round icon using this code:
<a class="facebook-share-button social-icons" href="#" target="_blank">
<i class="fab fa-facebook socialicons"></i>
</a>
Now your CSS will be:
.social-icons {
display: inline-block;border-radius: 25px;box-shadow: 0px 0px 2px #888;
padding: 0.5em;
background: #0D47A1;
font-size: 20px;
}
.socialicons{color: white;}

I like Dave Everitt's answer with the « line-height » but it only works by specifying the « height » and then we have to add « !important » to line-height ...
.cercle {
font-size: 2em;
width: 2em;
height: 2em;
text-align: center;
line-height: 2em!important;
background: #666;
color: #fff;
border-radius: 2em;
}

This is the best and most precise solution I've found so far.
CSS:
.social .fa {
margin-right: 1rem;
border: 2px #fff solid;
border-radius: 50%;
height: 20px;
width: 20px;
line-height: 20px;
text-align: center;
padding: 0.5rem;
}

Related

how to place font-awesome arrow icon center vertically

.btnup, .btndown{
display:inline-block;
font-size:20px;
background:#ddd;
border-radius:5px;
cursor:pointer;
width:25px;
line-height:30px;
height:30px;
color:#999;
text-align:center;
margin:0 5px;
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet"/>
<i class="fas fa-angle-up btnup" id='btnup'></i>
<i class="fas fa-angle-down btndown" id='btndown'></i>
How to place the arrows on center vertically ?
You can add top and bottom padding (and subtract those values from the heightsetting):
.btnup, .btndown{
display:inline-block;
font-size:20px;
background:#ddd;
border-radius:5px;
cursor:pointer;
width:25px;
line-height:30px;
height:20px;
color:#999;
text-align:center;
margin:0 5px;
padding: 5px 0 5px 0;
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet"/>
<i class="fas fa-angle-up btnup" id='btnup'></i>
<i class="fas fa-angle-down btndown" id='btndown'></i>
You could put the FA icon inside another element, which would be your gray background element, or you could add these CSS properties:
height:25px;
padding-top: 5px;
Basically reducing height, but compensating for it with padding-top, which forces the FA arrow icons down to the center of the gray area.
the line-height its being overriden by font-awesome, add !important to make it take yours
.btnup,
.btndown {
display: inline-block;
font-size: 20px;
background: #ddd;
border-radius: 5px;
cursor: pointer;
width: 25px;
line-height: 30px!important;
height: 30px;
color: #999;
text-align: center;
margin: 0 5px;
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" />
<i class="fas fa-angle-up btnup" id='btnup'></i>
<i class="fas fa-angle-down btndown" id='btndown'></i>
Play with height, and padding-top:
.btnup, .btndown{
display:inline-block;
font-size:20px;
background:#ddd;
border-radius:5px;
cursor:pointer;
width:25px;
line-height:10px;
padding-top: 5px;
height:24px;
color:#999;
text-align:center;
margin:0 5px;
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet"/>
<i class="fas fa-angle-up btnup" id='btnup'></i>
<i class="fas fa-angle-down btndown" id='btndown'></i>
I would wrap a <span> around the character and use flexbox to position it in the center.
.btnup,
.btndown {
display: flex;
justify-content: center; /* Horizontal alignment */
align-items: center; /* Vertical alignment */
font-size: 20px;
background: #ddd;
border-radius: 5px;
cursor: pointer;
width: 25px;
height: 30px;
color: #999;
margin: 5px;
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" />
<span class="btnup"><i class="fas fa-angle-up"></i></span>
<span class="btndown"><i class="fas fa-angle-down"></i></span>

How to get rid of the ribbon border by CSS?

I am trying to create a ribbon around a div using Bootstrap 4.
I can't clean the right border; on mobile, when the page is shrinked, my ribbon overflows to the right, out of parent div: https://jsfiddle.net/auj4q3a2/
Html:
<div class="container-fluid">
<div class="card profile-card">
<div class="container-fluid">
<div class="row user-social-detail">
<div class="col-lg-12 col-sm-12 col-12">
<i class="fa fa-facebook" aria-hidden="true"></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
<i class="fa fa-instagram" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
</div>
CSS:
.profile-card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 475px;
margin: auto;
text-align: center;
}
.user-social-detail{
margin: 0 -30px;
padding: 15px 0px;
background-color: #ffd280;
border-radius: 4px;
}
.user-social-detail a i{
color:#fff;
font-size:23px;
padding: 0px 5px;
}
.user-social-detail::before,
.user-social-detail::after {
content: '';
position: absolute;
z-index: -1;
left: -45px;
top: -28px;
display: block;
width: 40px;
height: 0px;
border: 30px solid transparent;
border-right: 20px solid #e5bd73;
border-bottom-color: transparent;
border-left-color: transparent;
}
.user-social-detail::after {
left: auto;
right: -45px;
border-left: 20px solid #e5bd73;
border-right: 30px solid transparent;
}
How can I fit the ribbon into the container on mobile, as on the left side?
Any suggestion or feedback will be welcomed and greatly appreciated.
Got it!
You have to add
overflow-x: hidden !important; to .container-fluid
EDIT:
Actually, only in 1st .container-fluid this is necessary, so you can add the following to your CSS file:
.container-fluid:first-of-type {
overflow-x: hidden !important;
}

CSS: Set color to parent's background-color

From the image below:
How would I make the text and icons inside the white boxes be the same color as the background of the big box?
Here is how the markup looks
<div class="class-item blue-bg">
<!--Heading stuff-->
<div class="class-item-actions">
<span class="pick-up-icon">
<i class="fa fa-female fa-lg"></i>
<i class="fa fa-child"></i>
</span>
<span class="full-day-icon blue">AM / PM</span>
<span class="unapproved-projects-icon blue">
2 <i class="fa fa-th-large fa-lg fa-fw class-item-action"></i>
</span>
<i class="fa fa-unlock fa-lg></i>
</div>
</div>
So essentially, how can I make it so somehow I don't need to add the blue class to full-day-icon and unapproved-projects-iconand instead it inherits the blue color from class-item's background-color?
EDIT: Here is the relevant CSS
.class-item {
padding: 10px;
width: 90%;
color: white;
margin-bottom: 5px;
cursor: pointer;
opacity: 0.85;
}
.full-day-icon {
font-weight: bold;
background: white;
padding: 5px;
border-radius: 3px;
font-size: 0.8em;
position: relative;
top: -1px;
}
.unapproved-projects-icon {
background-color: white;
padding: 5px;
border-radius: 3px;
font-size: 0.8em;
position: relative;
top: -1px;
}
If it's okay for you to use CSS Variables, here is a neat and simple way to do this:
.class-item {
/** Specify the BG color in one place. **/
--class-item-bg: #0076A5;
padding: 10px;
width: 90%;
background-color: var(--class-item-bg);
color: white;
margin-bottom: 5px;
cursor: pointer;
opacity: 0.85;
}
.full-day-icon {
font-weight: bold;
background: white;
color: var(--class-item-bg);
padding: 5px;
border-radius: 3px;
font-size: 0.8em;
position: relative;
top: -1px;
}
.unapproved-projects-icon {
background-color: white;
color: var(--class-item-bg);
padding: 5px;
border-radius: 3px;
font-size: 0.8em;
position: relative;
top: -1px;
}
You can check this fiddle to see how you can then use JavaScript to change the property so that it affects all the CSS rules where it is used.
You can't inherit different properties in CSS. So a child div wouldn't be able to inherit the background-color of it's parent for it's color property.
.parent {
background-color: red;
}
.child {
color: inherit-background-color /* Not a way to do this without a preprocessor */
}
Why not just apply the styles directly?
.full-day-icon {
color: #0076A5;
}
.class-item {
padding: 10px;
width: 90%;
background-color: #0076A5;
color: white;
margin-bottom: 5px;
cursor: pointer;
opacity: 0.85;
}
.full-day-icon {
font-weight: bold;
background: white;
color: #0076A5;
padding: 5px;
border-radius: 3px;
font-size: 0.8em;
position: relative;
top: -1px;
}
.unapproved-projects-icon {
background-color: white;
color: #0076A5;
padding: 5px;
border-radius: 3px;
font-size: 0.8em;
position: relative;
top: -1px;
}
<div class="class-item blue-bg">
<!--Heading stuff-->
<div class="class-item-actions">
<span class="pick-up-icon">
<i class="fa fa-female fa-lg"></i>
<i class="fa fa-child"></i>
</span>
<span class="full-day-icon blue">AM / PM</span>
<span class="unapproved-projects-icon blue">
2 <i class="fa fa-th-large fa-lg fa-fw class-item-action"></i>
</span>
<i class="fa fa-unlock fa-lg></i>
</div>
</div>

How to round font-awesome icons?

I am trying to round font-awesome icon. Please refer - http://jsfiddle.net/JfGVE/1704/
The problem is, not matter what, the rounded icon is more oval. Not able to make it a perfectly rounded. Below is the css code i have -
i {
display: inline-block;
background: gray;
color: white;
border-radius: 50%;
padding: 5px;
}
It's preferable to avoid setting fixed width and height in pixels. Here's a sollution using an extra div with after pseudo element to draw the circle, see DEMO
HTML:
<div class="container">
<i class="fa fa-close"></i>
</div>
CSS:
.container {
display: inline-flex;
align-items: center;
justify-content: center;
background-color: #555;
min-width: 2em;
border-radius: 50%;
vertical-align: middle;
}
.container:after {
content:'';
float: left;
width: auto;
padding-bottom: 100%;
}
Try to adjust height/width and reset line-height:
i {
display: inline-block;
background: gray;
color: white;
border-radius: 50%;
padding: 0.3em; /* adjust padding */
line-height: initial !important; /* reset line-height */
height: 1em;
width: 1em;
text-align:center;
}
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
<i class="fa fa-close"></i>
<br>
<i class="fa fa-camera-retro fa-lg"></i> fa-lg
<i class="fa fa-camera-retro fa-2x"></i> fa-2x
<i class="fa fa-close fa-3x"></i> fa-3x
<i class="fa fa-info fa-4x"></i> fa-4x
<i class="fa fa-camera-retro fa-5x"></i> fa-5x
[Edit] the icon size is not equal height/width.
So I changed the answer and added height: 1em; width: 1em; text-align: center;
Just use this:
<i class="fa fa-times-circle"></i>
or if you want you can try this too:
i.custom {
display: inline-block;
background: gray;
color: white;
border-radius: 50%;
}
i.custom:before,
i.custom:after {
display: inline-block;
vertical-align: middle;
height: 40px;
width: 40px;
line-height: 40px;
text-align: center;
}
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
<i class="custom fa fa-close"></i>
<i class="fa fa-times-circle"></i>

CSS justify three elements

I want to have a headline on the left side and buttons on the right side. Between I want a line.
.container {
background-image: url(http://www.deutsches-museum.de/fileadmin/Content/010_DM/020_Ausstellungen/100_Museumsinsel/030_Turm/030_Kunst/bild32.jpg);
height: 100px;
color: #fff;
}
.col-xs-8 {
border: 1px solid blue;
}
ul {
display: flex;
text-align: justify;
margin: 0;
padding: 0;
list-style-type: none;
}
ul li {
overflow: hidden;
white-space: nowrap;
}
li:first-child {
padding-right: 10px;
}
li:last-child {
padding-left: 10px;
font-size: 10px;
}
h2 {
margin: 10px 0 0 0;
font-size: 20px;
font-weight: normal;
}
.fa-stack-1x {
color: #777;
}
.line {
margin: 0 auto 5px;
border-bottom: 2px solid red;
width: 100%;
}
<div class="container">
<div class="row">
<div class="col-xs-8">
<div class="breadcrump">
<ul class="menu">
<li>
<h2>Here is a example Headline</h2>
</li>
<li class="line"></li>
<li>
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa fa-chevron-left fa-stack-1x"></i>
</span>
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa fa-chevron-right fa-stack-1x"></i>
</span>
</li>
</ul>
</div>
</div>
</div>
</div>
With justify the line overlays the Headline and the buttons and this is not what I want.
http://codepen.io/daluela/pen/aOVmGw
If I understand what you want, all you need to do is replace width:100% in .line with flex:1;.
Remove overflow:hidden from your list items.
http://codepen.io/anon/pen/gpXgRW
ul li {
overflow: hidden;/*remove this*/
white-space: nowrap;
}

Resources