02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Creating custom media queries

In the future it is very likely that we will be able to create our own media query rules. In this lecture we will explore this feature.

Keynotes:

  • Creating custom media queries
  • How to create a custom media query
  • How to use it.

properties:

responsive design,future of media queries, css4, media features, custom media queries

Video Transcript

00:00What are we going to be talking about in this lecture?
00:03Well, in this lecture, we're going to be talking about
00:05creating custom media queries.
00:07And again, this is a CSS4 feature, not available yet.
00:11Very interesting.
00:13Let's take a look at it and understand,
00:15well, let's start with the first basic question of,
00:18why do you want to create custom media queries?
00:20Now, this isn't a new feature more than a way
00:23for us to organize our code.
00:24And if we tend to have the same type of media queries
00:28used throughout our project,
00:30it could become really hard to manage
00:31and easy to create bugs.
00:33So the idea behind these custom media queries
00:36is really organization.
00:37And this organization will enable us
00:39to more cleanly define our CSS.
00:42And that's really their goal.
00:44So how do we use them and how do we create them?
00:47Probably it's going to be with the custom media rule.
00:51And the custom media rule,
00:52and I just want to show it,
00:53is very simple really to follow
00:54and could really make our code a lot easier to see.
00:59Our CSS cleaner, more simple,
01:01especially as we move into this world
01:03that is very heavy on media queries.
01:05Now, the CSS media rule works in a basic way.
01:08You set the media, the custom media,
01:10you define a name.
01:12Now, I don't know if it's mandatory
01:13to put two minuses before the name
01:16or this is just a convention
01:17because the documentation doesn't display that yet.
01:20And it could be changed.
01:21So it seems like a good convention
01:23to make sure that everyone knows
01:24that this is your media type,
01:25but you could name it whatever name you want
01:27as long as it's not a reserved name.
01:30And then you define all the rules
01:31you want inside of the round bracket.
01:34That's it, you've created yourself a new media rule.
01:37Now that you have a new media rule,
01:38you could just go ahead and use it in any media query,
01:42such as in this case,
01:43we're just setting it into that rule specifically.
01:47Or if we wanted to,
01:47we could have combined that with other rules
01:50as many as we wanted to.
01:51So in many ways,
01:52it could cluster together a group of rules
01:54that we use often.
01:56So that's it, that's what custom media rules are.
02:00And I do think they will be implemented
02:02and it's gonna be a very wonderful addition
02:04or an organizational addition that we can't use yet.
02:07But it's very interesting to see that that's in the horizon.
02:11What are we gonna talk about in the next lecture?
02:13In the next lecture,
02:14we're gonna take a look at media query operators
02:17and we're gonna see what's changed there
02:19and what stayed the same.
02:20So we'll see you in the next lecture
02:22when we explore those media query operators
02:24in CSS level four.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!