How to center FontAwesome icon in css before content vertically - css

I am going crazy. I have read dozens of blog articles and different stackoverflow postings but I am unable to vertically center a FontAwesome icon which is placed as content inside a css before pseudo element of a link element.
This is my CSS Code:
a.button {
background-color: green;
padding: 5px 10px;
color: #ffffff;
cursor: pointer;
position: relative;
display: inline-block;
}
a.button.forward {
padding-right: 35px;
}
a.button.back {
padding-left: 35px;
}
a.button.back:before {
font-family: FontAwesome;
content: "\f100";
font-size: 1em;
position: absolute;
top: 0;
bottom: 0;
left: 10px;
}
And thats the HTML code:
<a class="button back">back to<br/>whatever</a>
Here you can find a fiddle which shows my problem: https://jsfiddle.net/r1vysfaf/1
UPDATE:
I want to avoid using javascript to solve the styling issue. Furthermore the text of the link is dynamic and therefore it is not a solution to use "constant magic" spacings for paddings/margin/top.

Use display: table for parent and table-cell for child and alter your css as following:
a.button {
background-color: green;
padding: 5px 10px;
color: #ffffff;
cursor: pointer;
position: relative;
display: table;
}
a.button.forward {
padding-right: 35px;
}
a.button.back {
padding-left: 10px;
}
a.button.back:before {
font-family: FontAwesome;
content: "\f100";
font-size: 1em;
line-height: 1em;
display: table-cell;
vertical-align: middle;
padding: 0 10px 0 0;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<a class="button back">back to<br/>whatever</a>

UPDATE
Added the forward button, plus position values in ems so an increase or decrease of font sizes or element will not offset the icon.
Instead of absolute , use relative on the pseudo-element.
FIDDLE
SNIPPET
a.button {
background-color: green;
padding: 5px 10px;
color: #ffffff;
cursor: pointer;
position: relative;
display: inline-block;
}
a.button.forward {
padding-right: 35px;
}
a.button.back {
padding-left: 35px;
}
a.button.back:before {
font-family: FontAwesome;
content: "\f100";
font-size: 1em;
position: relative;
top: .625em;
bottom: 0;
right: 1.25em;
}
a.button.forward:after {
font-family: FontAwesome;
content: "\f101";
font-size: 1em;
position: relative;
top: -.5em;
left: 1.25em;
}
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css'>
<a class="button back">Back to<br/>whatever</a>
<a class="button back" style='font-size: 1.5em'>Font-size is<br/>increased by 50%</a>
<a class="button forward">Next to<br/>whatever</a>
<a class="button forward" style='font-size: .5em'>Font-size is<br/>decreased by 50%</a>

Related

multiple lines net icon

I am doing project on FreeCodeCamp and i want to put two lines next to icon, but one is under the icon, how can i solve it?
p {
display: inline;
vertical-align: top;
}
.icon-header {
font-size: 50px;
color: black;
margin-left: 5%;
display: inline-block;
vertical-align: top;
}
.icon-text {
display: inline-block;
float: left;
color: black;
font-size: 14px;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" >
<i class="fas fa-hand-holding-usd"><p><span class="icon-header">Low Prices</span><br><span class="icon-text">Our graphics cards are so cheap and affordable for everyone</span></p></i>
You can use position for icon
p {
display: inline-block;
vertical-align: middle;
padding-left: 44px;
position: relative;
}
p i{
position: absolute;
left: 0;
top: 15%;
font-size: 32px;
}
.icon-header {
font-size: 50px;
color: black;
display: block;
vertical-align: top;
}
.icon-text {
display: block;
float: left;
color: black;
font-size: 14px;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" >
<p><i class="fas fa-hand-holding-usd"></i> <span class="icon-header">Low Prices</span><span class="icon-text">Our graphics cards are so cheap and affordable for everyone</span></p>

HTML: Table row highlight

I followed Creating CSS3 Circles connected by lines to create circles-connected-by-lines as row elements of a HTML Table. I have also enabled row highlighting on hover.
My code can be found here:
`https://codepen.io/bhaktaonline/pen/XzoVPr`
The problem is when I hover and the row is highlighted, I am loosing the lines that are connecting the circles. (in this case, the line connecting the two circles vanishes in the highight color).
Appreciate some insight on the problem.
This behaviour is a result of the negative value you have specified for the z-index property of the pseudo-element li::before.
Remove this z-index property declared on li::before, instead declare a z-index value on the list items (li.data), since it is a positioned element already (position: relative), a z-index property value will apply, .eg:
li.data {
width: 2em;
height: 2em;
text-align: center;
line-height: 2em;
border-radius: 2em;
background: dodgerblue;
margin: 0 1em;
display: inline-block;
color: white;
position: relative;
/* additional */
z-index: 1;
}
Code Snippet Demonstration:
ul.bigger {
font-size: 1.3em;
}
ul.highlight-active li.active::before {
font-size: 1.6em;
background: green;
}
li.data {
width: 2em;
height: 2em;
text-align: center;
line-height: 2em;
border-radius: 2em;
background: dodgerblue;
margin: 0 1em;
display: inline-block;
color: white;
position: relative;
/* additional */
z-index: 1;
}
li.ack {
width: 2em;
height: 2em;
text-align: center;
line-height: 2em;
border-radius: 2em;
background: MediumSeaGreen;
margin: 0 1em;
display: inline-block;
color: white;
position: relative;
}
li::before {
content: '';
position: absolute;
top: .9em;
left: -4em;
width: 4em;
height: .2em;
background: Gray;
}
li:first-child::before {
display: none;
}
.active {
background: dodgerblue;
}
.active~li {
background: lightblue;
}
.active~li::before {
background: lightblue;
}
body {
font-family: sans-serif;
padding: 2em;
}
.table {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
th,
td {
text-align: left;
padding: 8px;
}
.row1 {
border: 1px solid #ddd;
padding: 8px;
}
.retransmission {
background-color: #0;
}
tr:nth-child(odd) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ffff99;
}
.row2 {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
<h2 id="ack_summary">Summary</h2>
<table style="width: 100%;">
<tr>
<th>Data/Ack Distribution - transfer 1, Packets 17 - 25</th>
</tr>
<tr>
<td>
<br>
<ul class="bigger highlight-active">
<li class="data">3</li>
<li class="ack">3</li>
</ul>
<br>
<h4>Cumulative Ack's distribution</h4>
<div id="chartContainer121" class="chartContainer"></div>
</td>
</tr>
</table>
Edit
In light of recent developments (as mentioned in the comments), rather declare the z-index property on the nested table cell tag, e.g:
td {
z-index: 9;
position: relative; /* required */
}
This way, any nested element will not be obscured by the containing element's background-color property. (expand updated code snippet below to observe this behaviour).
In addition, you can restore the negative z-index value initially declared on li::before.
ul.bigger {
font-size: 1.3em;
}
ul.highlight-active li.active::before {
font-size: 1.6em;
background: green;
}
li.data {
width: 2em;
height: 2em;
text-align: center;
line-height: 2em;
border-radius: 2em;
background: dodgerblue;
margin: 0 1em;
display: inline-block;
color: white;
position: relative;
}
li.ack {
width: 2em;
height: 2em;
text-align: center;
line-height: 2em;
border-radius: 2em;
background: MediumSeaGreen;
margin: 0 1em;
display: inline-block;
color: white;
position: relative;
}
li::before{
content: '';
position: absolute;
top: .9em;
left: -4em;
width: 4em;
height: .2em;
background: Gray;
z-index: -1;
}
li:first-child::before {
display: none;
}
.active {
background: dodgerblue;
}
.active ~ li {
background: lightblue;
}
.active ~ li::before {
background: lightblue;
}
body {
font-family: sans-serif;
padding: 2em;
}
.table {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
.row1 {
border: 1px solid #ddd;
padding: 8px;
}
.retransmission {
background-color: #0;
}
tr:nth-child(odd){background-color: #f2f2f2;}
tr:hover {background-color: #ffff99;}
.row2 {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
/* Additional */
td {
z-index: 9;
position: relative;
}
<h2 id="ack_summary">Summary</h2>
<table style="width: 100%;">
<tr>
<th>Data/Ack Distribution - transfer 1, Packets 17 - 25</th>
</tr>
<tr>
<td>
<br>
<ul class="bigger highlight-active">
<li class="data">3</li>
<li class="ack">3</li>
<li class="data">5</li>
<li class="ack">2</li>
</ul>
<br>
<h4>Cumulative Ack's distribution</h4>
<div id="chartContainer121" class="chartContainer"></div>
</td>
</tr>
</table>
I'd recommend further reading to understand the stacking context and how this generally applies to the z-index property:
Understanding CSS z-index - CSS | MDN
z-index - CSS | MDN
The stacking context - CSS | MDN

I want to recreate this quote in css

Hello i am a beginner in css and i want to recreate this:
this is my current start,i don`t know how to put the ' " '
#rectangle{
width: 100%;
height: 230px;
background-color:darkcyan;
display: block;
margin: 0px;
}
#rectangle p{
padding-top: 85px;
padding-left: 60px;
padding-right: ;
font-family: roboto_bold;
text-transform: uppercase;
margin: 0 auto;
display: block;
font-size: 38px;
color: aliceblue
}
`
Try to use a :before, something like this should give you an approximative result
#rectangle p:before {
content: '"';
position: absolute;
color: yellow;
font-size: 2em;
transform: translateY(-100%);
}
As a beginner the inclusion of other libraries or pseudo elements may be tricky. Here's a rather straightforward start.
.blue-box {
background: #2edfd2;
padding: 10px 40px;
width: 300px;
}
.lquote {
color: #ace941;
font-size: 60px;
height: 20px;
}
.underline {
background-color: #ace941;
height: 4px;
width: 20px;
}
.fine-print {
margin: 4px 0 0;
font-size: .6em;
}
<div class="blue-box">
<div class="lquote">“</div>
<p>Knowing I was adopted may have made me feel more independent, but I have never felt abandoned. My parents made me feel special.
<div class="underline"></div>
<p class="fine-print">Steve Jobs, 2009</p>
</div>
There can be many ways of doing this, one of which is that you can use icons.
Like I personally use fontawesome.
You can get many icons of different sizes just use them with an online css file.
http://fontawesome.io/icon/quote-left/
This is the link to the quotes that you want to insert
I created a prototype for you.
https://codepen.io/djmayank/pen/opYeyo
#rectangle{
width: 100%;
height: 230px;
background-color:darkcyan;
display: block;
margin: 0px;
}
#rectangle p{
padding-top: 5px;
padding-left: 60px;
padding-right: ;
font-family: roboto_bold;
text-transform: uppercase;
margin: 0 auto;
display: block;
font-size: 38px;
color: aliceblue
}
.fa {
color:#abe941;
margin-top:3%;
margin-left:10%;
}
<div id="rectangle">
<i class="fa fa-quote-left fa-2x" aria-hidden="true"></i>
<p>Loreim ispum Loreim ispumLoreim ispum Loreim </p>
</div>
<script src="https://use.fontawesome.com/8d594f9226.js"></script>

How do I create a share-able header with css content image that is vertically aligned?

I'm trying to implement something similar to GitHub's shareable headers (hover over a header in the README at the bottom of a repo and a link icon appears). I'm using pseudo selectors and a generated content image.
The problem is vertical alignment. The anchor tag is 29px tall while the heading is 25px. I tried to make the line height of the anchor tag 25px but the alignment was still off.
Demo on CodePen
<a href="#heading" title="Share me!" class="hover-link">
<h3 id="heading" class="share-heading">Some awesome heading</h3>
</a>
.share-heading {
display: inline;
}
a.hover-link {
content: "";
line-height: 25px;
}
a.hover-link:hover:after {
content: url(data:URI.......);
}
You can do this with another pseudo-element and a attribute as the content.
.share-heading {
display: inline-block;
padding-left: 25px;
margin: 0;
padding: 0;
vertical-align:middle;
}
a.hover-link {
display: inline-block;
vertical-align: top;
content: "";
color: #279ACB;
text-decoration: none;
margin: 25px;
border:1px dotted grey;
position: relative;
height: 25px;
}
a.hover-link:hover::after {
position: absolute;
content:attr(title);
top:110%;
left:50%;
transform:translateX(-50%);
border:1px solid lightblue;
height: 1.5rem;
line-height: 1.5rem;
width:auto;
white-space: no-wrap;
display: block;
padding:0 1rem;
background: lightgrey;
border-radius: .3rem;
box-shadow: 0 0 2px 1px black;
}
a.hover-link:before {
display: inline-block;
vertical-align: middle;
content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gwJDikbmKUOeQAAAnxJREFUSMft1k2IV1UYx/GP4xsm6WhCainmoptoBMGhIBhS6A0JSUlcmRCcVYajYLWpGWaVi8peRG5WUESbkhRFaONKRO8olBAcWjhFuNAaS8zIsZk2z8C/Ycb/jC3zrg7nPvd8z/N7fuc5l9sPqrqZVtXN9HZx025x8TvwAB7CfPyKM/ih5DT0nyFV3SzDdjyN+zEb1/A9DmJ/yenyLUOqulmCvdiI6biAASzGSvyJ99BXcro6+l3HFACd+AjPB+BIwLZgEz7EnMhy3ZQzqepmHg7hMczE19hecvq5JWY5PkMXPsauktNvMGMSgA7ci/14B7NwouR0YUzoJZwIyGosRHtIuOh1bA7QTAyiv6qbXpwuOd1okX5OjEda1+loU4PDeAX3YRhX0IkncQxPRaawCs/G+Bx+uWlNqrpZjANYH1MncRY/YUkUehm+xRPhrvdDqqvYUnI6OmEmUcB3WwBH8SXuxGDJqRtvhGw/Ym1sqAtDeBvHJ3RXVTdz0YeXw6aHsAN7wroD2In+kKwT27Am5NyLnpLTlZvV5EE8E4DDeKnkNIDPY5EVcR4+xVZ0BwD24bWxgH9BooAPowoZelvOwTG8gPO4C4+HPPfgMnrRXXL6a7wazxgDXBASnsfF0Rclp+tV3XyBU3g0MoLroX9/yWl4Iqe2Qoajm45gUYvnR0F/V3UzOwwxd1SiktPpKbX6qm4ewSfh+T14C79H3KpwTleEH8COktMf7SBjT/x30fgq7I4740zsfEPMD+EDvDpRDdreJ1XdLEUPXhzHfdeif705noumdDNWdbMorPxcZHMjsvwK30xGokm3+qpu7g7HjeBSyWnw//1X8w/hH8KtVkNhtAAAAABJRU5ErkJggg==);
}
<a href="{{}}#heading" title="Share me!" class="hover-link">
<h3 id="heading" class="share-heading">Some awesome heading</h3>
</a>

spans inside div running off page

I've seen some posts about this issue, but nothing's working for me right now. I have a div inside of which are many spans. The spans are running off the page. Can anyone help me please wrap the spans to keep them on the page?
HTML:
<div id="creditsbar">
<span class="title">Writing</span> <span class="name">Bob, Mary</span>
<span class="smallsquare">■</span>
<span class="title">Editing</span>
<span class="name">Mary, Bob</span>
<span class="smallsquare">■</span>
<span class="title">Design</span>
<span class="name">Bob</span>
<span class="smallsquare">■</span>
<span class="title">Development</span>
<span class="name">Mary</span>
<span class="smallsquare">■</span>
</div>
CSS:
#creditsbar {
width: 100%;
background color: lightgray;
color: #333;
font-family: "Muli", Helvetica, Arial;
padding-left: 20%;
max-height: 10%;
position: absolute;
bottom: 0;
left: 0;
z-index: 3;
padding-bottom: 10px;
max-width: 100%;
vertical-align: top;
}
#creditsbar span {
word-wrap: normal;
display: inline-block;
}
#creditsbar .title {
text-transform: uppercase;
font-size: 80%;
font-weight: 600;
padding-right: 5px;
}
#creditsbar .name {
}
#creditsbar .smallsquare {
padding: 0 10px;
}
It's because of padding-left: 20%; inside
#creditsbar {
width: 100%;
color: #333;
font-family: "Muli", Helvetica, Arial;
padding-left: 20%;
}
remove that line and it will work fine
else use box-sizing: border-box; as suggested by #Andy

Resources