Hi there, I can tell from your face that you wish this was a video about tuning things on and off depending on, if it was mobile or tablet. You're in luck my friend, on tablet view, we've got box one, two, all the way through to 10, all of them, but on desktop, because we've got three columns across, I only want nine. I want to turn 10 off, and it's gone, look. Then on mobile we want it to, box one, two, three, four, and then I turn the chunk of them off, and just turn 10 back on, just for kicks.
So this video is going to show you how to turn things on and off using CSS and Media Queries , depending if you're on mobile or tablet, the short version is, basically just apply a special class with display:none. Apply it to the things you want to turn off, and it will turn off, but for the long version, and all the good stuff, hang about, let's jump in and work out how to do it.
To add it we need to create a Class in our CSS that turns it off, and then apply that Class towards the thing you want to turn off. So the style in our case is, remember, on Desktop view - let's zoom out - is I want nine of them showing, so it's nice and even. I don't want that extra one hanging out which it currently does, there's this guy, don't want you there. These, and then-- so when we get to this view, we can turn our 10 back on, even though I've only got 8 here. 10 will fill it up still nicely, but in our mobile, I want to turn them all back on, because it doesn't really matter how many I have. So let's have a look at doing that.
We're going to create a Class. We're going to call this one 'Hide Desktop only'. It's a bit long, I wouldn't call it this, I'd probably call it H or Hide D. Just to make it smaller, but we'll try and make it really explicit, so it's really easy to work out in this Class. And all we're going to do is say 'display', we've done Block, we've done Inline Block, we've done Flex, we're going to do None, goodbye. So it's in my kind of global stuff, which means I'm targeting Desktop. If you want to turn it off for tablet, you'd probably change the name of it and have it in here.
Actually we might do that in this video, just to really kind of explain what we're doing. So now I need to-- because it's really long, I'm just going to copy it, apply it to something, so box 10 here, we're going to add two Classes. So make sure there's a space between the two separate Classes. Make sure it's inside your quotation marks, and hopefully now, on this view here, it's going to turn off. It's gone, on Desktop view, but it's gone on this view as well, tablet and mobile. It's because of that kind of flow. It flows through here, and there's nothing else telling it to come back on.
So what we have to do is grab all of this, including the curly brace, and make sure, when you are pasting this, we leave that guy there. He needs to be there, the kind of closing of this Media Query, and I paste this in, and I want to turn it, Display to Block, to show it up again. I don't need to tell it for this, because it will flow through on to mobile hopefully. So on Desktop, I've got nine, I can't scroll down any further. On tablet though, here we go, box 10 appeared. Then on mobile it should be there as well.
Let's just say, on mobile we need to turn a bunch of them off, because it's just, maybe it's scrolling really long, maybe you've got like 50, and on tablet you've got 40, but on mobile you just want 10. Let's just pretend that that's what we want to do. So in VS code we need to create another Class, and I only want to activate it at mobile. So before the last curly brace there, I'm going to say, I want one called 'Hide mobile only'. I'm not sure why I put mobile only, just call that, seems simpler. Same thing, display:none. And because it's linked into this CSS it's only to what you apply it to, but it's going to take effect, kind of make sense?
So what am I going to do? I'm going to do some multiple cursors, which is 'Command Option' on my Mac, or 'Control Option’ on a PC'. You’re sick of me telling shortcuts, aren't you? Space, and I'm going to call this, well I'm not going to call it, I'm going to grab 'Hide mobile', hopefully all of these are going to turn off. 10's not, it's going to be there, because I left that off this little group. Let's have a look. So, Desktop view, I've got nine. Teleview, I've got all 10, and then on mobile I've got, we've got one, two, three, four, and ten. All right, we're making responsive stuff. It's not very pretty but we know how to add text and images.
We're going to do it for this site, because responsive images are quite important, we'll get on to that next, but I hope you're getting used to using Media queries, both to do text changes but also to do things like structural changes, and turn things on and off. Now we've just done simple things like turning boxes on and off. You could completely change your website for mobile. It might be important that, when people are searching for your site, like I do it for my New Zealand business, it's more of like a sit down classroom business, right? So people come do Adobe courses or Web Design courses, but actually physically turn up.
So what we do is, when they're viewing it on desktop we show them information, because we know that likelihood is, they're looking to buy a course, we give them information about that, but when they're on the mobile, we've changed the Home Page to be very clear, our address and phone number, because that's more useful for somebody on their mobile, when they're normally rushing to try and, they're late for the class or they can't find the building. So you could turn on a huge-- you can turn Divs completely on and off, that have a nice cool map in it, or directions, or make the phone number really clear on the Home Page. It's not really useful on the Desktop view but be really cool to have on mobile.
All right, you get the idea. We're turning things on and off using display:none, that one. All right, I'll see you in the next video.