Add glyphicon to headings - css

Like in this answer I'm trying to add icon to h3 tag. Here is a result:
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<h1>Play it! <span class="glyphicon glyphicon-play text-primary"/></h1>
Also jsfiddle available.
But inside h3 tag the icon becomes too big. I would prefer something like this:
How can I make the icon smaller?

According to your HTML just add the CSS:
h1 span.glyphicon-play{
font-size: 0.5em;
vertical-align: 5px;
}

Change the font-size of the glyphicon
h1 .glyphicon {
font-size:.5em;
}
JSfiddle Demo

<h1>Play it! <span class="glyphicon glyphicon-play" style="font-size:15px;"></span></h1>
Try This code

There are many possible ways, one way is to write css for it, as mentioned in the above replies. Another possible way is using <small> tag. This would be answer if you don't want to dynamically decrease the font-size in css. Another solution is to give it a new class btn-sm especially if this is a button.
http://jsfiddle.net/agqqft99/10/

<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<h1>Play it! <span class="glyphicon glyphicon-play text-primary"/></h1>

Related

How to use the new Material Design Icon themes: Outlined, Rounded, Two-Tone and Sharp?

Google has revamped its Material Design Icons with 4 new preset themes:
Outlined, Rounded, Two-Tone and Sharp, in addition to the regular Filled/Baseline theme:
But, unfortunately, it doesn't say anywhere how to use the new themes.
I've been using it via Google Web Fonts by including the link:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
And then using the required icon as suggested in the documentation:
<i class="material-icons">account_balance</i>
But it always shows the 'Filled/Baseline' version.
I've tried doing the following to use the Outlined theme instead:
<i class="material-icons">account_balance_outlined</i>
<i class="material-icons material-icons-outlined">account_balance</i>
and, changing the Web Fonts link to:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons&style=outlined" rel="stylesheet">
etc. But it doesn't work.
And there's no point in taking shots in the dark like that.
tl;dr: Has anyone tried using the new themes? Does it even work like the baseline version (inline html tag)? Or, is it only meant to be downloaded as SVG or PNG formats?
Update (31/03/2019) : All icon themes work via Google Web Fonts now.
As pointed out by Edric, it's just a matter of adding the google web fonts link in your document's head now, like so:
<link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp" rel="stylesheet">
And then adding the correct class to output the icon of a particular theme.
<i class="material-icons">donut_small</i>
<i class="material-icons-outlined">donut_small</i>
<i class="material-icons-two-tone">donut_small</i>
<i class="material-icons-round">donut_small</i>
<i class="material-icons-sharp">donut_small</i>
The color of the icons can be changed using CSS as well.
Note: the Two-tone theme icons are a bit glitchy at present.
Update (14/11/2018) : List of 16 outline icons that work with the "_outline" suffix.
Here's the most recent list of 16 outline icons that work with the regular Material-icons Webfont, using the _outline suffix (tested and confirmed).
(As found on the material-design-icons github page. Search for: "_outline_24px.svg")
<i class="material-icons">help_outline</i>
<i class="material-icons">label_outline</i>
<i class="material-icons">mail_outline</i>
<i class="material-icons">info_outline</i>
<i class="material-icons">lock_outline</i>
<i class="material-icons">lightbulb_outline</i>
<i class="material-icons">play_circle_outline</i>
<i class="material-icons">error_outline</i>
<i class="material-icons">add_circle_outline</i>
<i class="material-icons">people_outline</i>
<i class="material-icons">person_outline</i>
<i class="material-icons">pause_circle_outline</i>
<i class="material-icons">chat_bubble_outline</i>
<i class="material-icons">remove_circle_outline</i>
<i class="material-icons">check_box_outline_blank</i>
<i class="material-icons">pie_chart_outlined</i>
Note that pie_chart needs to be "pie_chart_outlined" and not outline.
This is a hack to test out the new icon themes using an inline tag. It's not the official solution.
As of today (July 19, 2018), a little over 2 months since the new icons themes were introduced, there is No Way to include these icons using an inline tag <i class="material-icons"></i>.
+Martin has pointed out that there's an issue raised on Github regarding the same: https://github.com/google/material-design-icons/issues/773
So, until Google comes up with a solution for this, I've started using a hack to include these new icon themes in my development environment before downloading the appropriate icons as SVG or PNG. And I thought I'd share it with you all.
IMPORTANT: Do not use this on a production environment as each of the included CSS files from Google are over 1MB in size.
Google uses these stylesheets to showcase the icons on their demo page:
Outline:
<link rel="stylesheet" href="https://storage.googleapis.com/non-spec-apps/mio-icons/latest/outline.css">
Rounded:
<link rel="stylesheet" href="https://storage.googleapis.com/non-spec-apps/mio-icons/latest/round.css">
Two-Tone:
<link rel="stylesheet" href="https://storage.googleapis.com/non-spec-apps/mio-icons/latest/twotone.css">
Sharp:
<link rel="stylesheet" href="https://storage.googleapis.com/non-spec-apps/mio-icons/latest/sharp.css">
Each of these files contain the icons of the respective themes included as background-images (Base64 image-data). And here's how we can use this to test out the compatibility of a particular icon in our design before downloading it for use in the production environment.
STEP 1:
Include the stylesheet of the theme that you want to use.
Eg: For the 'Outlined' theme, use the stylesheet for 'outline.css'
STEP 2:
Add the following classes to your own stylesheet:
.material-icons-new {
display: inline-block;
width: 24px;
height: 24px;
background-repeat: no-repeat;
background-size: contain;
}
.icon-white {
webkit-filter: contrast(4) invert(1);
-moz-filter: contrast(4) invert(1);
-o-filter: contrast(4) invert(1);
-ms-filter: contrast(4) invert(1);
filter: contrast(4) invert(1);
}
STEP 3:
Use the icon by adding the following classes to the <i> tag:
material-icons-new class
Icon name as shown on the material icons demo page, prefixed with the theme name followed by a hyphen.
Prefixes:
Outlined: outline-
Rounded: round-
Two-Tone: twotone-
Sharp: sharp-
Eg (for 'announcement' icon):
outline-announcement, round-announcement, twotone-announcement, sharp-announcement
3) Use an optional 3rd class icon-white for inverting the color from black to white (for dark backgrounds)
Changing icon size:
Since this is a background-image and not a font-icon, use the height and width properties of CSS to modify the size of the icons. The default is set to 24px in the material-icons-new class.
Example:
Case I: For the Outlined Theme of the account_circle icon:
Include the stylesheet:
<link rel="stylesheet" href="https://storage.googleapis.com/non-spec-apps/mio-icons/latest/outline.css">
Add the icon tag on your page:
<i class="material-icons-new outline-account_circle"></i>
Optional (For dark backgrounds):
<i class="material-icons-new outline-account_circle icon-white"></i>
Case II: For the Sharp Theme of the assessment icon:
Include the stylesheet:
<link rel="stylesheet" href="https://storage.googleapis.com/non-spec-apps/mio-icons/latest/sharp.css">
Add the icon tag on your page:
<i class="material-icons-new sharp-assessment"></i>
(For dark backgrounds):
<i class="material-icons-new sharp-assessment icon-white"></i>
I can't stress enough that this is NOT THE RIGHT WAY to include the icons on your production environment. But if you have to scan through multiple icons on your in-development page, it does make the icon inclusion pretty easy and saves a lot of time.
Downloading the icon as SVG or PNG sure is a better option when it comes to site-speed optimization, but font-icons are a time-saver when it comes to the prototyping phase and checking if a particular icon goes with your design, etc.
I will update this post if and when Google comes up with a solution for this issue that does not involve downloading an icon for usage.
For angular material you should use fontSet input to change the font family:
<link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp"
rel="stylesheet" />
<mat-icon>edit</mat-icon>
<mat-icon fontSet="material-icons-outlined">edit</mat-icon>
<mat-icon fontSet="material-icons-two-tone">edit</mat-icon>
...
As of 27 February 2019, there are CSS fonts for the new Material Icon themes.
However, you have to create CSS classes to use the fonts.
The font families are as follows:
Material Icons Outlined - Outlined icons
Material Icons Two Tone - Two-tone icons
Material Icons Round - Rounded icons
Material Icons Sharp - Sharp icons
See the code sample below for an example:
body {
font-family: Roboto, sans-serif;
}
.material-icons-outlined,
.material-icons.material-icons--outlined,
.material-icons-two-tone,
.material-icons.material-icons--two-tone,
.material-icons-round,
.material-icons.material-icons--round,
.material-icons-sharp,
.material-icons.material-icons--sharp {
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
.material-icons-outlined,
.material-icons.material-icons--outlined {
font-family: 'Material Icons Outlined';
}
.material-icons-two-tone,
.material-icons.material-icons--two-tone {
font-family: 'Material Icons Two Tone';
}
.material-icons-round,
.material-icons.material-icons--round {
font-family: 'Material Icons Round';
}
.material-icons-sharp,
.material-icons.material-icons--sharp {
font-family: 'Material Icons Sharp';
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500|Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp">
</head>
<body>
<section id="original">
<h2>Baseline</h2>
<i class="material-icons">home</i>
<i class="material-icons">assignment</i>
</section>
<section id="outlined">
<h2>Outlined</h2>
<i class="material-icons-outlined">home</i>
<i class="material-icons material-icons--outlined">assignment</i>
</section>
<section id="two-tone">
<h2>Two tone</h2>
<i class="material-icons-two-tone">home</i>
<i class="material-icons material-icons--two-tone">assignment</i>
</section>
<section id="rounded">
<h2>Rounded</h2>
<i class="material-icons-round">home</i>
<i class="material-icons material-icons--round">assignment</i>
</section>
<section id="sharp">
<h2>Sharp</h2>
<i class="material-icons-sharp">home</i>
<i class="material-icons material-icons--sharp">assignment</i>
</section>
</body>
</html>
Or view it on Codepen
EDIT: As of 10 March 2019, it appears that there are now classes for the new font icons:
body {
font-family: Roboto, sans-serif;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500|Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp">
</head>
<body>
<section id="original">
<h2>Baseline</h2>
<i class="material-icons">home</i>
<i class="material-icons">assignment</i>
</section>
<section id="outlined">
<h2>Outlined</h2>
<i class="material-icons-outlined">home</i>
<i class="material-icons-outlined">assignment</i>
</section>
<section id="two-tone">
<h2>Two tone</h2>
<i class="material-icons-two-tone">home</i>
<i class="material-icons-two-tone">assignment</i>
</section>
<section id="rounded">
<h2>Rounded</h2>
<i class="material-icons-round">home</i>
<i class="material-icons-round">assignment</i>
</section>
<section id="sharp">
<h2>Sharp</h2>
<i class="material-icons-sharp">home</i>
<i class="material-icons-sharp">assignment</i>
</section>
</body>
</html>
EDIT #2: Here's a workaround to tint two-tone icons by using CSS image filters (code adapted from this comment):
body {
font-family: Roboto, sans-serif;
}
.material-icons-two-tone {
filter: invert(0.5) sepia(1) saturate(10) hue-rotate(180deg);
font-size: 48px;
}
.material-icons,
.material-icons-outlined,
.material-icons-round,
.material-icons-sharp {
color: #0099ff;
font-size: 48px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500|Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp">
</head>
<body>
<section id="original">
<h2>Baseline</h2>
<i class="material-icons">home</i>
<i class="material-icons">assignment</i>
</section>
<section id="outlined">
<h2>Outlined</h2>
<i class="material-icons-outlined">home</i>
<i class="material-icons-outlined">assignment</i>
</section>
<section id="two-tone">
<h2>Two tone</h2>
<i class="material-icons-two-tone">home</i>
<i class="material-icons-two-tone">assignment</i>
</section>
<section id="rounded">
<h2>Rounded</h2>
<i class="material-icons-round">home</i>
<i class="material-icons-round">assignment</i>
</section>
<section id="sharp">
<h2>Sharp</h2>
<i class="material-icons-sharp">home</i>
<i class="material-icons-sharp">assignment</i>
</section>
</body>
</html>
Or view it on Codepen
As of 12/05/2020, You need to
1. include CSS:
<link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp" rel="stylesheet">
2. Use it like this:
<i class="material-icons">account_balance</i>
<i class="material-icons material-icons-outlined">account_balance</i>
<i class="material-icons material-icons-two-tone">account_balance</i>
<i class="material-icons material-icons-sharp">account_balance</i>
<i class="material-icons material-icons-round">account_balance</i>
Note: For example, to use outlined style, You need to specify material-icons AND material-icons-outlined classes.
If you already have material-icons working in your web project, just need to update your reference in the html file and the used class for icons:
html reference:
Before
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
After
<link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp"
rel="stylesheet" />
material icons class:
After that just check wich className are you using:
Before:
<i className="material-icons">weekend</i>
After:
<i className="material-icons-outlined">weekend</i>
that works for me... Pura vida!
What worked for me is using _outline not _outlined after the icon name.
<mat-icon>info</mat-icon>
vs
<mat-icon>info_outline</mat-icon>
The webfonts link works now, in all browsers!
Simply add your themes to the font link separated by a pipe (|), like this
<link href="https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Outlined" rel="stylesheet">
Then reference the class, like this:
// class="material-icons" or class="material-icons-outlined"
<i class="material-icons">account_balance</i>
<i class="material-icons-outlined">account_balance</i>
This pattern will also work with Angular Material:
<mat-icon>account_balance</mat-icon>
<mat-icon class="material-icons-outlined">account_balance</mat-icon>
None of the answers so far explains how to download the various variants of that font so that you can serve them from your own website (WWW server).
While this might seem like a minor issue from the technical perspective, it is a big issue from the legal perspective, at least if you intend to present your pages to any EU citizen (or even, if you do that by accident). This is even true for companies which reside in the US (or any country outside the EU).
If anybody is interested why this is, I'll update this answer and give some more details here, but at the moment, I don't want to waste too much space off-topic.
Having said this:
I've downloaded all versions (regular, outlined, rounded, sharp, two-tone) of that font following two very easy steps (it was #Aj334's answer to his own question which put me on the right track) (example: "outlined" variant):
Get the CSS from the Google CDN by directly letting your browser
fetch the CSS URL, i.e. copy the following URL into your browser's
location bar:
https://fonts.googleapis.com/css?family=Material+Icons+Outlined
This will return a page which looks like this (at least in Firefox 70.0.1 at the time of writing this):
/* fallback */
#font-face {
font-family: 'Material Icons Outlined';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialiconsoutlined/v14/gok-H7zzDkdnRel8-DQ6KAXJ69wP1tGnf4ZGhUce.woff2) format('woff2');
}
.material-icons-outlined {
font-family: 'Material Icons Outlined';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-moz-font-feature-settings: 'liga';
-moz-osx-font-smoothing: grayscale;
}
Find the line starting with src: in the above code, and let your browser fetch the URL contained in that line, i.e. copy the following URL into your browser's location bar:
https://fonts.gstatic.com/s/materialiconsoutlined/v14/gok-H7zzDkdnRel8-DQ6KAXJ69wP1tGnf4ZGhUce.woff2
Now the browser will download that .woff2 file and offer to save it locally (at least, Firefox did).
Two final remarks:
Of course, you can download the other variants of that font using the same method. In the first step, just replace the character sequence Outlined in the URL by the character sequences Round (yes, really, although here it's called "Rounded" in the left navigation menu), Sharp or Two+Tone, respectively. The result page will look nearly the same each time, but the URL in the src: line of course is different for each variant.
Finally, in step 1, you even can use that URL:
https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp
This will return the CSS for all variants in one page, which then contains five src: lines, each one with another URL designating where the respective font is located.
New themes are probably not (yet?) part of the Material Icons font. Link.
The Aj334's recent edit works perfectly.
google CDN
<link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp" rel="stylesheet">
Icon Element
<i class="material-icons">donut_small</i>
<i class="material-icons-outlined">donut_small</i>
<i class="material-icons-two-tone">donut_small</i>
<i class="material-icons-round">donut_small</i>
<i class="material-icons-sharp">donut_small</i>
I was unsatisfied that until know Google hasn't yet released their new designs as font or svg icon set. Therefore I put together a small npm package to solve the problem.
https://www.npmjs.com/package/ts-material-icons-svg
Simply import the icons you wanna use and add them to your registry. This also supports tree shaking since only those icons are added to your project that you really want and/or need.
npm i --save https://github.com/MarcusCalidus/ts-material-icons-svg.git
to use two tone icons for example
import {icon_edit} from 'ts-material-icons-svg/dist/twotone';
matIconRegistry.addSvgIcon(
'edit',
domSanitizer.bypassSecurityTrustResourceUrl(icon_edit),
);
In your html template you now can use the new icon
<mat-icon svgIcon="edit"></mat-icon>
Put in head link to google styles
<link href="https://fonts.googleapis.com/icon?family=Material+Icons+Outlined" rel="stylesheet">
and in body something like this
<i class="material-icons-outlined">bookmarks</i>
Setting up the Two-tone color:
As described above you can use the color css key except for materials Two-tone theme which seems to be glitchy ;-)
A workaround is described in one of several angular material github issue's by using a custom css filter. This custom filter can be generated here.
E.g.:
Html:
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Round|Material+Icons+Two+Tone|Material+Icons+Sharp">
<i class="material-icons-two-tone red">home</i>
css:
.red {
filter: invert(8%) sepia(94%) saturate(4590%) hue-rotate(358deg) brightness(101%) contrast(112%);
}
Attachments:
Working Angular Stackblitz
Codepen example
Codepen CSS filter Generator
I ended up using IcoMoon app to create a custom font using only the new themed icons I required for a recent web app build. It's not perfect but you can mimic the existing Google Font functionality pretty nicely with a little bit of setup. Here's a writeup:
https://medium.com/#leemartin/how-to-use-material-icon-outlined-rounded-two-tone-and-sharp-themes-92276f2415d2
If someone is feeling daring, they could convert the entire theme using IcoMoon. Hell, IcoMoon probably has an internal process that would make it easy since they already have the original Material Icons set in their library.
Anyway, this isn't a perfect solution, but it worked for me.
Somewhat hilariously, Google has made a font that works correctly in Safari but not in Chrome. Here's the https://codepen.io/anon/pen/zbavza
<i class="material-icons-round red">warning</i>
In reference to https://stackoverflow.com/a/54902967/4740291 and not being able to change the color using css.
For Angular users (tested on v14):
If you want to change the globally used theme of icons to e.g. outlined, you can do this in your AppModule or wherever you need it:
export class AppModule {
constructor(private readonly iconRegistry: MatIconRegistry) {
const defaultFontSetClasses = iconRegistry.getDefaultFontSetClass();
const outlinedFontSetClasses = defaultFontSetClasses
.filter(fontSetClass => fontSetClass !== 'material-icons')
.concat(['material-icons-outlined']);
iconRegistry.setDefaultFontSetClass(...outlinedFontSetClasses);
}
}
defaultFontSetClasses also includes mat-ligature-font class name, which you need to keep in order to render the icons properly if you're using [fontIcon] property binding in your <mat-icon> elements.
also, remember to load the Material Icons Outlined stylesheet:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Outlined" rel="stylesheet" />
per https://material.angular.io/components/icon/api#MatIconRegistry

Resize icons in WordPress header

I'm trying to make these social media icons larger in my Wordpress menu.
I used this code as a custom link in the menu:
<i class="fa fa-instagram"></i>
fa stands for FontAwesome, so your icons are a font. You can change their size by using font-size in your CSS.
just add font size to parent HTML tag. It'll works.
a { font-size: 100px; }
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<i class="fa fa-instagram"></i>

How do I put icon and text paragraph in one line?

I want to put my font awesome icon and text paragraph into one line. How can I fix this code?
<div class="date" style="display: inline-block;">
<i class="fa fa-user-o" aria-hidden="true" style="float: left;"></i>
<p style="display: inline-block; text-align: right;float: left;" >10/01/2018</p>
</div>
Julia, remove all your floats:
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="date">
<i class="fa fa-user-o" aria-hidden="true"></i>
<p style="display: inline-block" >10/01/2018</p>
</div>
Also you might make it this way:
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="date">
<i class="fa fa-user-o"> 10/01/2018</i>
</div>
If your currently used font of the website has Icons Cheatsheet then you can have a set of icons of the third party. Here I would like to introduce “Font Awesome Icons”. This is a good-looking and popular set of icons.
To use this set, you need to add this code to the head section in your website (via OIW Blog):
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
– After adding CSS, you can use this code to put in the HTML which shows icons (you can apply this method to the part you use Cheatsheet of the font as mentioned above. Some fonts have unique way of using)
<i class="fa fa-user-o"></i>
If you don’t want the code in the HTML, you can just use CSS. With CSS you need to find the Class or ID of the part that displays icon and after that use the below CSS code to display it. Here I display the EDIT icon of the third party “Font Awesome Icons” before (::before) the title, along with 2 properties of padding-right and font-style (you can also display it after the title by using after property): #ohiwill
.date .fa::before {
font-family: "FontAwesome";
content: "\f044";
padding-right: 5px;
font-style: normal;
}

How to select a span inside a div?

I'm having an issue coloring a span with css. Everything is working fine on the webpage however when I try to select a span in a div it doesn't work. Am I missing something dumb here?
<!doctype html>
<html>
<head>
<title>Test</title>
<link href="style/mainstyle.css" rel="stylesheet" type="text/css">
<script src= https://code.jquery.com/jquery-latest.min.js></script>
</head>
<body>
<header>
<h1>TEST</h1>
</header>
<main>
<div class = "tab1 triad">
<script src="primejs.js"></script>
<span class="red"><h2>Type in a number and I'll check if it is prime:</h2></span>
<input class = "primeNum" type = "text">
<button class = "submit">Submit</button>
<span class = "result">
<h2>What I found: <span class = "answer">?</span></h2>
</span>
</div>
</main>
</body>
and here is the css:
.tab1 span.red {
color: RED;
font-size: 100;
}
Cleaned up your HTML, you had a some stray and missing tags.
Bin demo
<div class="tab1 triad">
<span class="red">
<h2>Type in a number and I'll check if it is prime:</h2>
</span>
<input class="primeNum" type="text">
<button class="submit">Submit</button>
<span class="result">
<h2>What I found: <span class="answer">?</span></h2>
</span>
</div>
And your css was missing the px after 100
.tab1 span.red {
color: red;
font-size: 100px;
}
try this
.red {
color: red;
font-size: 100px; /* specify a unit like px, em, ... */
}
First of all, the HTML code you have posted is not valid. You can use the official W3C validator to check if you like. The main issue is the spaces either side of your = when declaring attributes. Spaces are only ever used in between different attributes. Also, h2 elements are block type elements, and are therefore not allowed inside of an inline element (e.g., span).
Secondly, the CSS is also not all valid. Firstly, there is no need to make anything uppercase, as is shown for the colour name. color:red; will work just fine. Also, you have not specified any units of measurement for the font-size property. I assume you intended for the text to be at 100pt, in which case you need to use font-size:100pt;. Other valid units of measurement include px, cm and rem.
I recommend you read information on the Mozilla Developer Network for examples if you would like to learn more. It includes accurate pages about HTML elements, CSS properties and JavaScript.
Edit:
The following would help to fix the HTML:
Change doctype to DOCTYPE, which improves compatibility.
Move all script tags into the head tag.
Ensure that all inputs, buttons, etc. are inside of form elements.
Remove spaces around = signs.
Make the href attribute of the stylesheet link tag the second attribute, and make the rel attribute the first. This is primarily for consistency.

Use CSS to make a span not clickable

<html>
<head>
</head>
<body>
<div>
<a href="http://www.google.com">
<span>title<br></span>
<span>description<br></span>
<span>some url</span>
</a>
</div>
</body>
</html>
I am pretty new to CSS, I have a simple case like the above. I would like to make the "title" and "some url" clickable but want to make description as non-clickable. Is there any way to do that by applying some CSS on the span so that whatever inside that span, it is not clickable.
My constraint is that, I do not want to change the structure of the div, instead just applying css can we make a span which is inside an anchor tag, not clickable ?
Actually, you can achieve this via CSS. There's an almost unknown css rule named pointer-events. The a element will still be clickable but your description span won't.
a span.description {
pointer-events: none;
}
there are other values like: all, stroke, painted, etc.
ref: http://robertnyman.com/2010/03/22/css-pointer-events-to-allow-clicks-on-underlying-elements/
UPDATE: As of 2016, all browsers now accept it: http://caniuse.com/#search=pointer-events
UPDATE: As of 2022, browsers behavior may have changed, another option can be:
a {
pointer-events: none;
}
a span:not(.description) {
pointer-events: initial;
}
Not with CSS. You could do it with JavaScript easily, though, by canceling the default event handling for those elements. In jQuery:
$('a span:nth-child(2)').click(function(event) { event.preventDefault(); });
CSS is used for applying styling i.e. the visual aspects of an interface.
That clicking an anchor element causes an action to be performed is a behavioural aspect of an interface, not a stylistic aspect.
You cannot achieve what you want using only CSS.
JavaScript is used for applying behaviours to an interface. You can use JavaScript to modify the behaviour of a link.
In response to piemesons rant against jQuery, a Vanilla JavaScript(TM) solution (tested on FF and IE):
Put this in a script tag after your markup is loaded (right before the close of the body tag) and you'll get a similar effect to the jQuery example.
a = document.getElementsByTagName('a');
for (var i = 0; i < a.length;i++) {
a[i].getElementsByTagName('span')[1].onclick = function() { return false;};
}
This will disable the click on every 2nd span inside of an a tag.
You could also check the innerHTML of each span for "description", or set an attribute or class and check that.
This is the simplest way I would have done it. Without bordering about CSS or javascript :
<html>
<head>
</head>
<body>
<div>
<p>
<a href="http://www.google.com">
<span>title<br></span>
</a>
<span>description<br></span>
<a href="http://www.google.com">
<span>some url</span>
</a>
</p>
</div>
</body>
</html>
You can replace the tag with anything you want.
Yes you can....
you can place something on top of the link element.
<!DOCTYPE html>
<html>
<head>
<title>Yes you CAN</title>
<style type="text/css">
ul{
width: 500px;
border: 5px solid black;
}
.product-type-simple {
position: relative;
height: 150px;
width: 150px;
}
.product-type-simple:before{
position: absolute;
height: 100% ;
width: 100% ;
content: '';
background: green;//for debugging purposes , remove this if you want to see whats behind
z-index: 999999999999;
}
</style>
</head>
<body>
<ul>
<li class='product-type-simple'>
<a href="/link1">
<img src="http://placehold.it/150x150">
</a>
</li>
<li class='product-type-simple'>
<a href="/link2">
<img src="http://placehold.it/150x150">
</a>
</li>
</ul>
</body>
</html>
the magic sauce happens at product-type-simple:before class
Whats happening here is that for each element that has class of product-type-simple you create something that has the width and height equal to that of the product-type-simple , then you increase its z-index to make sure it will place it self on top of the content of product-type-simple. You can toggle the background color if you want to see whats going on.
here is an example of the code
https://jsfiddle.net/92qky63j/
CSS relates to visual styling and not behaviour, so the answer is no really.
You could however either use javascript to modify the behaviour or change the styling of the span in question so that it doesn't have the pointy finger, underline, etc. Styling it like that will still leave it clickable.
Even better, change your markup so that it reflects what you want it to do.
Using CSS you cannot, CSS will only change the appearance of the span. However you can do it without changing the structure of the div by adding an onclick handler to the span:
<html>
<head>
</head>
<body>
<div>
<a href="http://www.google.com">
<span>title<br></span>
<span onclick='return false;'>description<br></span>
<span>some url</span>
</a>
</div>
</body>
</html>
You can then style it so that it looks un-clickable too:
<html>
<head>
<style type='text/css'>
a span.unclickable { text-decoration: none; }
a span.unclickable:hover { cursor: default; }
</style>
</head>
<body>
<div>
<a href="http://www.google.com">
<span>title<br></span>
<span class='unclickable' onclick='return false;'>description<br></span>
<span>some url</span>
</a>
</div>
</body>
</html>

Resources