Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Changing icon states

From: Deploying Icon Fonts for the Web

Video: Changing icon states

Often, icon fonts will have icons that represent For example, the chunky mobile font that we've been using throughout our course And then I want to give it, an ID of icon, and remember down because the icon font was designed with these to save that, go back out to my browser and now you'll notice that color adds a little bit of an extra element to changing the icon states.

Changing icon states

Often, icon fonts will have icons that represent the various states of UI elements or widgets. For example, the chunky mobile font that we've been using throughout our course has several sets of icons that are designed to indicate UI state of elements. For example, we have the battery here that indicates the charger of the battery. We have Wi-Fi and signal strength. And right down here we've got the icons that we're going to use in our example which is the state of the volume. So mute all the way to, to loud.

Well, you know, one of the things that we have to think about. When we start trying to display the states of various UI elements with these icons is how's that going to work with the existing deployment strategy that we've got for our icons. What I mean by that is it's really common when people are. Working with UI elements to use certain frameworks or have certain structures built in. It's really incompatible with the way you're already displaying your icons. Now, I'm not talking about using things like the hover pseudo class selector.

You can certainly do that and that's going to change the stay of an icon based on user interaction, I'm talking more about widgets like the slider that you're seeing here. Or certain types of form elements and you want to make some changes to those. Often those have built in constraints on styling and functionality. So, sometimes you actually have to change deployment strategies, and use multiple deployment strategies for displaying icons in your site. You might have one for interactive widgets. And then you might have another one for displaying just normal icons on the page.

So in this exercise what we're going to do, is we're going to take this slider widget right here, and we're going to indicate the changes in states by showing the volume icon on the right hand side. Okay, so here I am in my code editor. And I'm in the state.htm file, in the 04_03 directory. The first thing I want to do is, give you guys an idea of, of what's going on here in terms of the HTML page, and the structure, and what we're working with. So I'm using Google's CDN Code CDN Network, to bring in J Query, ant the J Query U-I libraries.

I know they recommend you doing it without the protocol, but I have found that if I am testing locally, and I don't have that protocol, and I'm not working with a local server, then it fails. So I always put the protocol on there for exercise files in case people are testing locally. All right, if I scroll down I can see that I've got a div with an ID of slider UI. That's a wrapper div for this interior slider right there. Below that I've got a function written. And this one is, it's a really simple little function.

What it does is it's it's initiating the slider. It's passing some parameters in terms of, you know, it starts with zero. It increments in values of 25 and it goes up to 75. You know it's volume so if I were to really have been thinking about it I would of made it go up to 11, but it is what it is. And then every time somebody interacts with the slider it's firing off this function. What it's doing is it's going to go out and find the element with an ID of icon. It's going to remove any classes that it has and then it's going to add whatever class That matches the UI value in the classes variable.

So if I look up at the classes variable, you can see that matching the the UI value is zero, 25, 50, and 75. And then we have classes for volumes one, two, three and four. So what should stand out to you here is that, you know, prior to this we've used a deployment strategy pretty much that is using the data icon attribute to display icons. Well the way that this particular function is set up that's not going to be possible. Now we could certainly probably modify this function to enable that but what I'm trying to illustrate here is that a lot of times you have to come up with an alternate strategy.

Okay so I'm going to scroll up a little bit. And in order to display our icon I'm still going to use a span tag. So I'm just going to go ahead and create a new span tag. Right after the slider div. And we still want it to conform to our accessibility requirements. So I'm going to give it an aria hidden value equal to true. And then I want to give it, an ID of icon, and remember down here, we are targeting the element of icon, so this is, this is the expand tag that we were talking about, and then finally I'm going to give it an initial class, although this will be striped out, when, somebody starts interacting, of volume one.

All right, I'm going to close my span tag out and save that. Now, right now, if I go back into my browser and refresh this and nothing's really going on here. And that's because we haven't styled this at all or assigned any type of an icon to this value. So what I'm going to do is open up the base.css And I'm going to scroll down towards the bottom where you guys will notice some slight differences from the way that we've been doing things normally. Okay, the first thing you're going to notice is we actually have two normalized blocks here.

The first one is for spans that are using the data icon attitude. The second one is for ones using the aria hidden attribute because, regardless of whether we're using data-icon or not, we are always going to use aria-hidden. And so, because of that I can just go ahead and just do the regular normalization through that, whereas some of these specifics like displaying it block and 64 pixels, those'll be reserved for displaying icons using the data-icon attribute. All right the only other styling we've got going on here at this time or our slider elements, the slider UI and the slider itself.

And that's just basically to make sure that it's going to play nice within the area that have defined for it. All right, so now what we need to do is display the icons. And to do this, we're going to go back to more of a class based approach. So, if we recall, the function is going to assign a new class every single time somebody interacts with it. So, that's what we're going to take advantage of we going to type in span.vol1. So that's the initial class. And we're going to use again generated content to display our icons. We're not changing that part of the strategy.

But this time we can be explicit in what we're setting. And what we're going to do, is we're going to set the volume, which is found at, and I need to do an escape here. I could do the HTML entity, but I actually like doing this one better when I, when I'm able to do it. And it's e069, that's the muted version of the volume icon. And then we're just going to do some basic styling of this. We're going to do font-size of 32 pixels. We're going to do a line-height of one just to sort of normalize that out.

And we'll do a display of in-line block. All right, I'm going to go ahead and save this. And then because, you know, I always like to save time when I can, I'm going to copy and paste this, one, two, three more times. And I'm going to go through and change the class name to vol2, vol3 and vol4, and then one at a time I'm going to go in, to the content declaration, and I'm going to lower that by one. So, from 69 to 68, 68 to 67, 67 to 66, and if I go back into my font, you can see why we're doing that.

There's 69, 68, 67 and 66, okay, I'm going to save this. Go back out to my browser and indeed now I can see there is my mute icon showing up. Then I grab this slider and move it. The states change and because the icon font was designed with these to be the exact same position and the exact same size. It does a really nice job of representing the state change. Now what's really nice about this is you can get as creative with this as you want. For example, I could go back into each of these guys and assign a, a slightly different color to them.

So, for the first one, for example, I could come in and do a color of, say, pound 888 which is just a real neutral grey so maybe that's you know, sort of disabled if you will, and then because that's the mute,. With the next one I might start increasing the amount of color that's in this, so maybe this one is like A06 four, six, five I'd love to let you guys think that, you know, that I'm just making up those colors on the fly, but the truth of the matter is that I kind of played around with this before I started recording.

I know that's a big shock to you guys. The next one, I'm going to give the color of CF4649. Essentially what I'm doing is I'm making it get a little bit more red. Each time, finally color for the last one. I'm going to make that FF0004, save that, go back out to my browser and now you'll notice that color adds a little bit of an extra element to changing the icon states. So once you've mapped out a deployment strategy, it's really just up to you to decide exactly how you want to style and represent those different icon states.

You know, I'm not recommending what I did there as a best practice of interacting with Widgets, or even as a best practice of displaying the icon states at various levels What I really want to get you thinking about is the fact that occasionally, you're going to run into times within an application or a project where you have constraints that fall outside of the strategy that you've developed for deploying your icon fonts. When that happens, you need to sit down and really organize your thoughts. Think about how you're going to approach this and how you're going to write those styles that aren't going to overwrite or interfere with anything else you're doing within your site regarding your icons.

Show transcript

This video is part of

Image for Deploying Icon Fonts for the Web
Deploying Icon Fonts for the Web

21 video lessons · 1702 viewers

James Williamson
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Deploying Icon Fonts for the Web.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.