How to put background to FA icons - html

I want to put a background to my FA icons, but something like a low opacity circle around them.
Code:
.social {display:block; float:left; margin:auto; height: 50px; font-size: 12px; padding-top:7px; width: 200px; text-align: center; text-decoration: none; border-bottom: 5px solid black;}
.social i {cursor: pointer; display: inline-block; position: relative; transition: 0.5s;}
.social i:after {content: '\00bb'; position: absolute; opacity: 0; top: -1px; right: -50px; transition: 0.2s;}
.social:hover i {padding-right: 20px; color: white;}
.social:hover i:after {opacity: 1; right: 0;}
.my-facebook {background: transparent; color: #3b5998;}
.my-instagram {background: transparent; color: white;}
.my-codepen{background: transparent; color: black;}
.my-github{background: transparent; color: #f5f5f5;}
.my-linkedin{background: transparent; color: #00a0dc;}
.my-fcc{background: transparent; color: #006400;}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div id="buttons">
<a class="social my-codepen" target='_blank' href="#"><i class="fa fa-codepen fa-3x"></i></a>
<a class="social my-github" target='_blank' href="#"><i class="fa fa-github fa-3x"></i></a>
<a class="social my-facebook" target='_blank' href="#"><i class="fa fa-facebook fa-3x"></i></a>
<a class="social my-fcc" target='_blank' href="#"><i class="fa fa-free-code-camp fa-3x"></i></a>
<a class="social my-linkedin" target='_blank' href="#"><i class="fa fa-linkedin fa-3x"></i></a>
<a class="social my-instagram" target='_blank' href="#"><i class="fa fa-instagram fa-3x"></i></a>
</div>
I've tried to change the "background" but it changes the whole square. I want only to give a circular background or a circular border around the icon itself.
Thanks to all!

You need to use stacked icons. I have modified your example for you below.
Code
.social {display:block; float:left; margin:auto; height: 50px; font-size: 12px; padding-top:7px; width: 200px; text-align: center; text-decoration: none; border-bottom: 5px solid black;}
.social i {cursor: pointer; display: inline-block; transition: 0.5s;}
.social i:after {content: '\00bb'; position: absolute; opacity: 0; top: -1px; right: -50px; transition: 0.2s;}
.social:hover i {padding-right: 20px; color: white;}
.social:hover i:after {opacity: 1; right: 0;}
.my-facebook {background: transparent; color: #3b5998;}
.my-instagram {background: transparent; color: black;}
.my-codepen{background: transparent; color: black;}
.my-github{background: transparent; color: black;}
.my-linkedin{background: transparent; color: #00a0dc;}
.my-fcc{background: transparent; color: #006400;}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div id="buttons">
<a class="social my-codepen" target='_blank' href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-codepen fa-stack-1x fa-inverse"></i>
</span>
</a>
<a class="social my-github" target='_blank' href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-github fa-stack-1x fa-inverse"></i>
</span>
</a>
<a class="social my-facebook" target='_blank' href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
</span>
</a>
<a class="social my-fcc" target='_blank' href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-free-code-camp fa-stack-1x fa-inverse"></i>
</span>
</a>
<a class="social my-linkedin" target='_blank' href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-linkedin fa-stack-1x fa-inverse"></i>
</span>
</a>
<a class="social my-instagram" target='_blank' href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-instagram fa-stack-1x fa-inverse"></i>
</span>
</a>
</div>
Jsfiddle Here

Related

HTML popup menu prevent overflow container

I have following code which show popupmenu when click on icon on each block, right now for the third block the menu overflow the black container, I need to display inside the container by shifting the menu div towards left side. Only the last column menu need to shift left for keeping the position inside the container.
How it's possible?
function myFunction(id) {
document.getElementById(id).classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("edit-dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.grid_container {
display: grid;
grid-template-columns: repeat(auto-fill, 150px);
grid-gap: 10px;
justify-content: center;
align-content: flex-start;
margin: 0 auto;
margin-top: 0px;
text-align: center;
margin-top: 10px;
width: 508px;
background: black;
}
.grid_block {
background-color: #269ad3 !important;
color: #efefef;
border: 1px solid #ccc;
width: 150px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.edit-dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 120px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.edit-dropdown-content a {
color: black;
padding: 5px 12px 5px 16px;
text-decoration: none;
display: block;
text-align: left;
font-size: 14px;
}
.w3-right {
float: right !important;
padding: 10px;
}
.w3-xlarge {
font-size: 25px;
}
.show {
display: block;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="pdf_parent_id" class="grid_container">
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu0')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu0" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu1')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu1" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu2')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu2" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu3')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu3" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
Here is the fiddle
https://jsfiddle.net/kvzbuLn9/
Possibly you can do this:
.w3-right {
position: relative;
}
#dropdown_menu3 {
bottom: 30px;
position: absolute;
}
EDIT: Use this code:
#dropdown_menu2{
position: absolute;
right: 10px;
}
Working example:
function myFunction(id) {
document.getElementById(id).classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("edit-dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.grid_container {
display: grid;
grid-template-columns: repeat(auto-fill, 150px);
grid-gap: 10px;
justify-content: center;
align-content: flex-start;
margin: 0 auto;
margin-top: 0px;
text-align: center;
margin-top: 10px;
width:508px;
background:black;
}
.grid_block {
background-color: #269ad3 !important;
color: #efefef;
border: 1px solid #ccc;
width: 150px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.edit-dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 120px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.edit-dropdown-content a {
color: black;
padding: 5px 12px 5px 16px;
text-decoration: none;
display: block;
text-align: left;
font-size: 14px;
}
.w3-right {
float: right !important;
padding:10px;
}
.w3-xlarge{
font-size:25px;
}
.show {display: block;}
.w3-right {
position: relative;
}
#dropdown_menu3 {
bottom: 30px;
position: absolute;
}
#dropdown_menu2{
position: absolute;
right: 10px;
}
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div id="pdf_parent_id" class="grid_container">
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu0')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu0" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu1')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu1" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu2')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu2" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu3')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu3" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
If your html is static and is not generated by some js code then you can use a straightforward approach - just add additional class to your menu container:
css:
.menu-icon-container {
position: relative;
}
.edit-dropdown-content--inside {
right: 23px;
top: 0;
}
html:
<div class="w3-right menu-icon-container">
<i onclick="myFunction('dropdown_menu2')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu2" class="edit-dropdown-content edit-dropdown-content--inside">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a>
</div>
</div>
You can add position: relative on the .grid-block so we can then add left: 30px on our dropdown. This should position them all to the left.
function myFunction(id) {
document.getElementById(id).classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("edit-dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.grid_container {
display: grid;
grid-template-columns: repeat(auto-fill, 150px);
grid-gap: 10px;
justify-content: center;
align-content: flex-start;
margin: 0 auto;
margin-top: 0px;
text-align: center;
margin-top: 10px;
width: 508px;
background: black;
}
.grid_block {
background-color: #269ad3 !important;
color: #efefef;
border: 1px solid #ccc;
width: 150px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
position: relative;
}
.edit-dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
left: 30px;
min-width: 120px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.edit-dropdown-content a {
color: black;
padding: 5px 12px 5px 16px;
text-decoration: none;
display: block;
text-align: left;
font-size: 14px;
}
.w3-right {
float: right !important;
padding: 10px;
}
.w3-xlarge {
font-size: 25px;
}
.show {
display: block;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="pdf_parent_id" class="grid_container">
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu0')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu0" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu1')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu1" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu2')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu2" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu3')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu3" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
We can also use the nth-child selector to target only the one at the end of the row.
function myFunction(id) {
document.getElementById(id).classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("edit-dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.grid_container {
display: grid;
grid-template-columns: repeat(auto-fill, 150px);
grid-gap: 10px;
justify-content: center;
align-content: flex-start;
margin: 0 auto;
margin-top: 0px;
text-align: center;
margin-top: 10px;
width: 508px;
background: black;
}
.grid_block {
background-color: #269ad3 !important;
color: #efefef;
border: 1px solid #ccc;
width: 150px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
position: relative;
}
.edit-dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
left: 120px;
min-width: 120px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.grid_block:nth-child(3n) .edit-dropdown-content {
left: 30px;
}
.edit-dropdown-content a {
color: black;
padding: 5px 12px 5px 16px;
text-decoration: none;
display: block;
text-align: left;
font-size: 14px;
}
.w3-right {
float: right !important;
padding: 10px;
}
.w3-xlarge {
font-size: 25px;
}
.show {
display: block;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="pdf_parent_id" class="grid_container">
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu0')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu0" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu1')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu1" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu2')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu2" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>
<div class="grid_block">
<div>
<h5>Title</h5>
<i class="fa fa-file-pdf-o"></i>
<h6 style="font-size:12px;">Subtitle</h6>
<div class="w3-right">
<i onclick="myFunction('dropdown_menu3')" class="dropbtn fa fa-ellipsis-v w3-xlarge"></i>
<div id="dropdown_menu3" class="edit-dropdown-content">
<a class="contextMenu"><i class="fa fa-edit"></i> Menu1</a>
<a class="contextMenu"><i class="fa fa-download"></i> Menu2</a>
<a class="contextMenu"><i class="fa fa-share"></i> Menu3</a>
<a class="contextMenu"><i class="fa fa-trash"></i> Menu4</a></div>
</div>
</div>
</div>

Font Awesome - how to put an icon inside a circle?

I'm trying to put some Font Awesome icons over a div element, making it look like a circle that contains the icons. There are in total three icons inside a circle each, and all the circle have to be next to each other. But when I try to do it the icons are not positioned correctly and the circles move out of place. I don't know what I'm doing wrong.
.python {
width: 200px;
height: 200px;
display: inline-block;
border-radius: 50%;
margin-left: 183px;
background-color: lightblue;
}
.fa-python{
font-size: 100px;
display: inline-block;
position: relative;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
<div class="python">
<i class="fab fa-python"></i>
</div>
Font Awesome already allow this, you don't need to do it yourself:
.custom .fa-circle:before {
border-radius: 50%;
background: linear-gradient(red, blue);
color: transparent;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
<span class="fa-stack fa-2x">
<i class="far fa-circle fa-stack-2x"></i>
<i class="fab fa-python fa-stack-1x"></i>
</span>
<span class="fa-stack fa-2x">
<i class="fas fa-circle fa-stack-2x" style="color:lightblue"></i>
<i class="fab fa-python fa-stack-1x "></i>
</span>
<span class="fa-stack fa-2x">
<i class="fas fa-circle fa-stack-2x" style="color:blue"></i>
<i class="fab fa-facebook-f fa-stack-1x fa-inverse"></i>
</span>
<span class="fa-stack fa-2x">
<i class="fas fa-circle fa-stack-2x" ></i>
<i class="fab fa-twitter fa-stack-1x fa-inverse"></i>
</span>
<span class="fa-stack fa-2x custom">
<i class="fas fa-circle fa-stack-2x" ></i>
<i class="fab fa-twitter fa-stack-1x fa-inverse"></i>
</span>
Related: https://fontawesome.com/how-to-use/on-the-web/styling/stacking-icons
Same code works for the V6 as well:
.custom .fa-circle:before {
border-radius: 50%;
background: linear-gradient(red, blue);
color: transparent;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.2.0/css/all.css">
<span class="fa-stack fa-2x">
<i class="far fa-circle fa-stack-2x"></i>
<i class="fab fa-python fa-stack-1x"></i>
</span>
<span class="fa-stack fa-2x">
<i class="fas fa-circle fa-stack-2x" style="color:lightblue"></i>
<i class="fab fa-python fa-stack-1x "></i>
</span>
<span class="fa-stack fa-2x">
<i class="fas fa-circle fa-stack-2x" style="color:blue"></i>
<i class="fab fa-facebook-f fa-stack-1x fa-inverse"></i>
</span>
<span class="fa-stack fa-2x">
<i class="fas fa-circle fa-stack-2x" ></i>
<i class="fab fa-twitter fa-stack-1x fa-inverse"></i>
</span>
<span class="fa-stack fa-2x custom">
<i class="fas fa-circle fa-stack-2x" ></i>
<i class="fab fa-twitter fa-stack-1x fa-inverse"></i>
</span>
I think is easier to just use flex
.python {
width: 200px;
height: 200px;
display: flex;
border-radius: 50%;
justify-content: center;
align-items: center;
}
or grid
{
display: grid;
place-content: center;
}

Make list of icons responsive with Bootstrap

I have this list of icons (fonts) lined up on the bottom of a section's page. On mobile, the line of icons overflows over on the right of that page. I would like to have 3 or 4 icons per row instead on smaller screen. I have tried multiple possibilities and the best I got was the line to be cut off (not having all icons show). Any cue would be greatly appreciated, I don't know what I'm doing wrong :-/
HTML:
<!--Skills-->
<div class="container">
<div class="icons text-center">
<ul>
<li><i class="fab fa-html5"></i></li>
<li><i class="fab fa-css3-alt"></i></li>
<li><i class="fab fa-js"></i></li>
<li><i class="fab fa-bootstrap"></i></li>
<li><i class="fab fa-sass"></i></li>
<li><i class="fab fa-less"></i></li>
<li><i class="fab fa-github"></i></li>
<li><i class="fab fa-wordpress"></i></li>
<li><i class="fab fa-adobe"></i></li>
<li><i class="fab fa-python"></i></li>
</ul>
</div>
</div>
As for CSS:
/*Skills*/
.icons {
padding: 0px 0px;
}
ul {
padding: 0;
margin: 0;
display: flex;
justify-content:space-around;
width: 700px;
margin-left: auto;
margin-right: auto;
}
ul li {
list-style: none;
font-size: 30px;
border-radius: 400px;
width: 50px;
height: 50px;
display: block;
text-align: center;
padding-top: 4px;
padding-bottom: 0px;
color: #2c3e50;
}
.icons > ul li {
flex: 1;
}
form ul li {
font-size: 15px;
width: inherit;
color: #ff0000;
text-align: left;
}
form ul {
margin-left: 0px;
margin-right: 0px;
height: 10px;
}
/*What I tried so far... some of them might be nonesense but I was desperate!*/
#media (max-width: 450px) {
.icons {
padding: 25px;
width: 25%;
flex-wrap: wrap;
position: absolute;
margin:auto;
justify-content: center;
align-items: center;
display:inline-block;
text-align: center;
overflow-x: hidden;
line-height: 1.2;
width: 100%;
margin-bottom: auto;
margin-left: auto;
margin-right: auto;
}
#media (max-width: 450px) {
.icons li {
width: 50%;
}
restructure your code to remove ul, li and let the default behavior manage this for;
working snippet below:
i {
list-style: none;
font-size: 30px;
border-radius: 400px;
width: 50px;
height: 50px;
display: block;
text-align: center;
padding-top: 4px;
padding-bottom: 0px;
color: #2c3e50;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.6/css/all.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
Do you really need ul, li ?
<hr/>
<div class="icons text-center">
<i class="fab fa-html5"></i>
<i class="fab fa-css3-alt"></i>
<i class="fab fa-js"></i>
<i class="fab fa-bootstrap"></i>
<i class="fab fa-sass"></i>
<i class="fab fa-less"></i>
<i class="fab fa-github"></i>
<i class="fab fa-wordpress"></i>
<i class="fab fa-adobe"></i>
<i class="fab fa-python"></i>
</div>
You could have done something this way
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="container text-center">
<span style="padding:5px">
<i class="fab fa-facebook-f"></i>
</span>
<span style="padding:5px">
<i class="fab fa-twitter"></i>
</span>
<span style="padding:5px">
<i class="fab fa-html5"></i>
</span> <span style="padding:5px">
<i class="fab fa-html5"></i>
</span> <span style="padding:5px">
<i class="fab fa-html5"></i>
</span> <span style="padding:5px">
<i class="fab fa-html5"></i>
</span> <span style="padding:5px">
<i class="fab fa-html5"></i>
</span> <span style="padding:5px">
<i class="fab fa-html5"></i>
</span> <span style="padding:5px">
<i class="fab fa-html5"></i>
</span>
<span style="padding:5px">
<i class="fab fa-facebook-f"></i>
</span>
<span style="padding:5px">
<i class="fab fa-twitter"></i>
</span> <span style="padding:5px">
<i class="fab fa-facebook-f"></i>
</span>
<span style="padding:5px">
<i class="fab fa-twitter"></i>
</span> <span style="padding:5px">
<i class="fab fa-facebook-f"></i>
</span>
<span style="padding:5px">
<i class="fab fa-twitter"></i>
</span>
</div>

Removing Space Between Anchor Tags [duplicate]

This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 5 years ago.
I'm having some troubles removing the white space between these 'social links' that I'm making.
Also I am having some troubles getting them centered correctly in the middle of the 'a' tag. I've tried using: margin: -30; or padding: -30 to try to pull the <i> tags closer to the top, which didn't work!
Why isn't this this working?
Here is my code:
#footer .footer-right {
float: right;
margin-right: 50px;
margin-top: 20px;
}
#footer .footer-right a {
height: 55px;
width: 55px;
text-align: center;
color: black;
padding: 5px 5px;
display: inline-block;
font-size: 3em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="footer-right">
<div class="social-links">
<div class="social-row soc-row-1">
<i class="fa fa-twitter" aria-hidden="true"></i>
<i class="fa fa-github" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>
</div>
<div class="social-row">
<i class="fa fa-stack-overflow" aria-hidden="true"></i>
<i class="fa fa-facebook" aria-hidden="true"></i>
<i class="fa fa-youtube" aria-hidden="true"></i>
</div>
</div>
</div>
Using display: inline-block introduces a margin between elements. Give a negative right margin to remove space.
#footer .footer-right a {
height: 55px;
width: 55px;
text-align: center;
color: black;
padding: 5px 5px;
display: inline-block;
font-size: 3em;
margin-right: -4px;
}
The amount of margin depends on the font size of the parent.
Another method is to skip the closing tag:
<a href="#" class="twitter"><i class="fa fa-twitter" aria-hidden="true"></i>
<a href="#" class="github"><i class="fa fa-github" aria-hidden="true"></i>
<a href="#" class="linkedin"><i class="fa fa-linkedin" aria-hidden="true"></i>
.footer-right {
margin-top: 20px;
}
.footer-right a {
height: 55px;
width: 55px;
text-align: center;
color: black;
padding: 5px 5px;
display: inline-block;
font-size: 3em;
margin-right: -4px;
}
.social-row{
text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="footer-right">
<div class="social-links">
<div class="social-row soc-row-1">
<i class="fa fa-twitter" aria-hidden="true"></i>
<i class="fa fa-github" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>
</div>
<div class="social-row">
<i class="fa fa-stack-overflow" aria-hidden="true"></i>
<i class="fa fa-facebook" aria-hidden="true"></i>
<i class="fa fa-youtube" aria-hidden="true"></i>
</div>
</div>
</div>

Unable to Create Space Between Font Awesome Icons

I am trying to get some space between my 4 fa-icons to spread them out more across the page. I'd like them to take up around 75% of the page. The HTML and accompanying CSS is shown below:
.fa-icons {
padding: 15px;
text-align: center;
}
.icon-background-face {
color: #3b5998;
}
.fa-facebook {
color: #fff;
}
.facebook i {
margin-right: 100px;
}
.icon-background-twit {
color: #00aced;
}
.fa-twitter {
color: #fff;
}
.icon-background-tube {
color: #bb0000;
}
.fa-youtube {
color: #fff;
}
.icon-background-env {
color: #000000;
}
.fa-envelope {
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div class="fa-icons">
<span class="fa-stack fa-5x">
<a href="" target="_blank">"
<i class="fa fa-circle fa-stack-2x icon-background-face fa-fw"></i>
<i class="fa fa-facebook fa-1x fa-stack-1x fa-fw"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="" target="_blank">
<i class="fa fa-circle fa-stack-2x icon-background-twit fa-fw"></i>
<i class="fa fa-twitter fa-1x fa-stack-1x fa-fw"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="" target="_blank">
<i class="fa fa-circle fa-stack-2x icon-background-tube"></i>
<i class="fa fa-youtube fa-1x fa-stack-1x"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="">
<i class="fa fa-circle fa-stack-2x icon-background-env"></i>
<i class="fa fa-envelope fa-1x fa-stack-1x"></i>
</a>
</span>
</div>
Just use margin like this:
.fa-stack {
margin-right: 10px; <-- change accordingly
}
Create a custom class name for the last div and add margin-right: 0; to prevent unwanted margin after that div.
You can simply add margin to the fas, see the following example:
.fa-icons {
padding: 15px;
text-align: center;
}
.fa-icons span {
margin: 0 20px;
}
.icon-background-face {
color: #3b5998;
}
.fa-facebook {
color: #fff;
}
.facebook i {
margin-right: 100px;
}
.icon-background-twit {
color: #00aced;
}
.fa-twitter {
color: #fff;
}
.icon-background-tube {
color: #bb0000;
}
.fa-youtube {
color: #fff;
}
.icon-background-env {
color: #000000;
}
.fa-envelope {
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div class="fa-icons">
<span class="fa-stack fa-5x">
<a href="" target="_blank">"
<i class="fa fa-circle fa-stack-2x icon-background-face fa-fw"></i>
<i class="fa fa-facebook fa-1x fa-stack-1x fa-fw"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="" target="_blank">
<i class="fa fa-circle fa-stack-2x icon-background-twit fa-fw"></i>
<i class="fa fa-twitter fa-1x fa-stack-1x fa-fw"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="" target="_blank">
<i class="fa fa-circle fa-stack-2x icon-background-tube"></i>
<i class="fa fa-youtube fa-1x fa-stack-1x"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="">
<i class="fa fa-circle fa-stack-2x icon-background-env"></i>
<i class="fa fa-envelope fa-1x fa-stack-1x"></i>
</a>
</span>
</div>
codepen
.fa-icons {
text-align: center;
width: 75%;
display: table;
margin-left: auto;
margin-right: auto;
overflow: hidden;
}
.fa-icons>span{
display: table-cell;
vertical-align:top;
}
.icon-background-face {
color: #3b5998;
}
.fa-facebook {
color: #fff;
}
.icon-background-twit {
color: #00aced;
}
.fa-twitter {
color: #fff;
}
.icon-background-tube {
color: #bb0000;
}
.fa-youtube {
color: #fff;
}
.icon-background-env {
color: #000000;
}
.fa-envelope {
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div class="fa-icons">
<span class="fa-stack fa-5x">
<a href="" target="_blank">
<i class="fa fa-circle fa-stack-2x icon-background-face fa-fw"></i>
<i class="fa fa-facebook fa-1x fa-stack-1x fa-fw"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="" target="_blank">
<i class="fa fa-circle fa-stack-2x icon-background-twit fa-fw"></i>
<i class="fa fa-twitter fa-1x fa-stack-1x fa-fw"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="" target="_blank">
<i class="fa fa-circle fa-stack-2x icon-background-tube"></i>
<i class="fa fa-youtube fa-1x fa-stack-1x"></i>
</a>
</span>
<span class="fa-stack fa-5x">
<a href="">
<i class="fa fa-circle fa-stack-2x icon-background-env"></i>
<i class="fa fa-envelope fa-1x fa-stack-1x"></i>
</a>
</span>
</div>