Adding a superscript font awesome icon using CSS classes - css

I have the following snippet of HTML..
<ul>
<li class="fa fa-balance-scale" id="test" />
</ul>
..with the associated CSS classes:
.fa {
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.fa-balance-scale:before {
/* font-awesome: balance-scale */
content: "\f24e"
}
.fa-hourglass-2:before,
.fa-hourglass-half::before {
/* font awesome: balance-scale, fa-hourglass-half */
content: "\f24e \f252";
}
.fa-lg {
font-size: 1.33333333em;
line-height: .75em;
vertical-align: -15%;
}
..and some JS to increase the size and append an hourglass after an event:
$("#test").addClass("fa-hourglass-half fa-lg")
..and I am looking to create the following (image):
Whilst I have managed it using the following...
<i class="fa" icon-before="&#xf24e" icon-after="&#xf252"></i>
i:before {
/*balance-scale*/
content: attr(icon-before);
position: relative;
font-size: 1.5em;
margin: 0.1em;
}
i:after {
/*fa-hourglass-half*/
content: attr(icon-after);
position: absolute;
font-size: -0.5em;
/*margin-bottom: 2.0em;*/
}
...it is not appropriate as I need to use CSS classes only. This is due to dependencies (and ensure compatibility) with other components of the application I am working on.
Is there anyone who can propose a possible solution using only CSS classes? Any advice or suggestions would also be greatly appreciated. Thank you.
With thanks to all and especially sheriffderek, this is the code which was used:
.fa {
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.fa.loading {
position: relative;
}
.fa.loading:after {
display: block;
position: absolute;
top: -8px;
right: -12px;
content: '\f252';
transform: scale(0.7, 0.7);
}
.fa-lg {
font-size: 1.33333333em;
line-height: .75em;
vertical-align: -15%;
}

If you are asking for an official 'font-awesome' way, I don't know it - but here's the logic behind how I'd try and do it.
First I would create a jsFiddle - and make sure that the font and other dependencies are loaded / so we're all on the same page: http://jsfiddle.net/sheriffderek/rqLkjmo3/2/ --- it looks like this link: http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css includes the #font inclusion and the css.
Then I would create some functionality to check:
<ul class='icon-list'>
<li class='icon fa fa-camera-retro' id='test'></li>
</ul>
<button rel='toggle'>toggle superscript</button>
jQuery in this case:
var $button = $('[rel="toggle"]');
$button.on('click', function() {
$('#test').toggleClass('waiting');
});
And then lay over something - in the top corner / is this font-awesome specific? / is there an hourglass-version of 'balance-scale' ? I don't know. I couldn't get .fa-balance-scale to work...
.icon-list {
padding: 1rem;
}
.fa.waiting {
position: relative;
}
.fa.waiting:after {
display: block;
position: absolute;
top: 0;
right: 0;
content: 'x'; /* whatevers */
color: red;
transform: translate(50%, -50%);
}
This logic should work for any type of graphic inclusion. Icons fonts were great when they were the best option, but that is no longer the case. Take a look at fontastic or something that will spit out a sprite sheet. : )

Related

How to change h2 span text boxes into rectangle shape?

As the title says i am trying to make two h2 and span text boxes have a rectangular shape for a website and i need help.
mine's looks like this:
but i want them to look like this:
h2 {
position: fixed;
top: 20rem;
left: 11rem;
text-align: right;
font-size: 1rem;
}
h2 span {
background-color: #556272;
color: #fff;
display: inline-block;
text-align: center;
font-style: normal;
padding: 2rem;
}
h2 span:first-child {
width: 200px;
height: 44px;
font-size: 20px;
}
h2 span:last-child {
transform: translate(-1rem, -1rem);
width: 200px;
height: 44px;
font-size: 15px;
}
<h2>
<span>Web</span> <br />
<span>Development</span>
</h2>
Just my take, but it seems like it'd be easier and more readable to do something like this:
h2 div {
/* various styles for background and colors */
background-color: #ccc; /* just an example */
}
h2 div.first-line {
display: block;
max-width: 200px; /* or whatever */
margin-left: 200px;
}
h2 div.second-line {
display: block;
max-width: 200px; /* or whatever */
margin-left: 100px;
}
<h2>
<div class='first-line'>Web</div>
<div class='second-line'>Development</div>
</h2>
Removing Defauilt styling
Headers by default have more margin on the top. You just want to normalize your styling.
html, body {
margin: 0;
}
This should do the trick, as it removes all margins from all elements. Just put it at the top of your stylesheet. But there are also some normalize.css defaults out there that remove all unwanted default styling.
You can also change the styling on the element itself, or remove all styling from it:
h2 {
all: unset;
}
But usually removing all default styling like this is not what you want. I'm just saying it's an option.
I usually just start styling by starting from something like this:
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
}
body {
font-family: Roboto, 'Helvetica Neue', sans-serif;
background-color: #eee;
/* Some other defaults, like maybe flex attributes depending on your layout. */
}
Tip: When using the browser development tools, you can inspect each tag and see all the styling it has. Try changing / removing things in there, until you've found the culprit of your issues.

FontAwesome icon not shown in CSS :after selector in Chrome?

This is my HTML:
<hr class="star-light">
This is my CSS:
hr.star-light:after {
color: #fff;
background-color: #EF672F;
}
hr.star-light:after, hr.star-primary:after {
content: "\f005";
display: inline-block;
position: relative;
top: -.8em;
padding: 0 .25em;
font-family: FontAwesome;
font-size: 2em;
}
It shows a hr with a white star in the middle in Firefox, but in Chrome its just a hr, no star is shown.
Any idea what I have to change in order to make it work in Chrome?
Thanks
hope this may help you.
Please try below CSS.
hr.star-light:after, hr.star-primary:after {
content: "\f005";
display: inline-block;
position: relative;
top: 0em; /* changed value from -.8em to 0em */
padding: 0 .25em;
font-family: FontAwesome;
font-size: 2em;
}
Is there any reason to assigned negative value to top property?
Please see codepen example - https://codepen.io/prakashrajotiya/pen/ZEzxKdJ?editors=1100

Invisible element with visible :after pseudo-element not working in IE11

I was able to use this hack: How can I replace text with CSS? --to replace a closing 'X' button on a lightbox from a third party library I'm using. It works great in all browsers but IE11. It seems IE hides both the element and the pseudo-element even though visibility: visible is set on the pseudo. If I toggle visibility using dev tools, they both show up.
Note: if the actual 'X' button were an actual 'X' character, I could easily style it as needed. Unfortunately, they use a symbol, so I have to resort to using this method to "replace" it with an actual X, to match the design standards of the site.
CSS for the button:
/* Hack to replace the close button text */
#_pendo-close-guide_ {
visibility: hidden;
}
#_pendo-close-guide_:after {
content:'X';
visibility: visible;
display: block;
position: absolute;
right: 6px;
top: 8px;
font-size: 17px;
font-weight: 200 !important;
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, sans-serif;
color: #444;
}
Any help would be much appreciated.
To get this working in IE, I had to use the old "text-indent: -9999px" trick:
/* Hack to replace the close button text */
#_pendo-close-guide_ {
text-indent: -9999px;
line-height: 0;
}
/* Hack to replace the close button text */
#_pendo-close-guide_:after {
content:'X';
position: relative;
right: 6px;
top: 4px;
line-height: initial;
text-indent: 0;
display: block;
font-size: 17px;
font-weight: 200 !important;
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, sans-serif;
color: #444;
}
My solution was inspired by #Tim's answer. However, I wasn't able to use text-indent due to my specific case so I used
.container {
position: relative;
left: -9999px;
}
.container:after {
position: relative;
left: 9999px;
}
and it worked in IE11 and other browsers.

Can't make font-awesome menu icon to be equivilant with neighboring menu links

The first link in my site's horizontal main menu is a home-icon taken from font-awsome. This icon + it's neighboring text, both appear higher\taller than the rest of the links in that menu.
I've tried to play with the Display\Vertical-align\Margin\min-height of the elements of both of them and nothing helped...
The problem could be seen directly when you enter my site, in any page. Here is a link to my site's homepage.
The font-icon css is:
.fa-home::before {
content: "";}
The main-menu links css is:
#superfish-1 .sf-depth-1 a {
color: #779573;
font-size: 13.5px;
text-align: right;}
Additional details:
This is a Drupal 7, RTL site.
Please help in making the font-awesome icon link homogenous in position\tallness to all other, Thanks,
Change this:
.fa{
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
transform: translate(0, 0);
}
to this:
.fa:before {
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
transform: translate(0, 0);
}
that should do the trick. So instead of having: .fa{} you have .fa:before{}
The convention with Font Awesome is to put the font in an <i> tag <i class="fa fa-home"></i> and place that next to the text.
If you can change the tag in your menu to:
<i class="fa fa-home"></i>בית you shouldn't need to make any css changes and the text should take on the size of the other list items.
Hope that helps.
Adding a fixed line-height to your sf-menu a tags would also fix it.
.sf-menu a {
display: block;
line-height: 1.8em;
position: relative;
}
Then you can play around with the position of the icon, whatever size you make the icon just increase the padding on the li.first a by another 20-25%;
li.first a {
text-align: center;
font-size: 0;
}
li.first .fa-home::before {
font-size: 2em;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

click on a transparent select don't work on firefox

I'm trying to get rid of the default select to use something more aligned to the style of my site.
I created a <button> to wrap the select. Gave it opacity: 0 and absolute positioning and sizing to make it fit the button. With some jquery i made it so that the active option appears also as the text of the button, in a <span>. It looks pretty nice.
The problem is that on chrome and safari works perfectly, on firefox instead quite not!
webkit listen to the click on the select even if it's not visible, moz don't (pretty curious about IE and opera). I really don't know how to solve this...
Here a fiddle with a reproduction of the problem:
http://jsfiddle.net/bakaburg1/YyvRf/2/
Any help is welcome.
You can use <div> instead of <button>
HTML:
<div class="btn btn-small select-container">
<select>
<option>title</option>
<option>date</option>
<option>author</option>
</select>
</div>
CSS:
.btn.btn-small{
padding-bottom: 2px;
padding-top: 2px;
color: #737373;
font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
font-size: 14px !important;
font-variant: small-caps;
font-weight: bold;
}
.btn.select-container {
position: relative;
padding-right: 24px;
}
.btn.select-container select {
position: absolute;
top: -1px;
left: 0;
height: 117%;
width: 100%;
opacity: 0;
filter: alpha(opacity=0);
z-index: 1000;
}
select.btn {
width: initial;
height: 23px;
padding-right: 20px;
-webkit-appearance: none;
}
select.btn:focus {
outline: none;
}
.select-container {
position: relative;
}
See it here: http://jsfiddle.net/YyvRf/3/

Resources