HomeНаука и техникаRelated VideosMore From: Lon Hosford

@media Link Tag CSS Media Query Mobile First Responsive Design

19 ratings | 2902 views
You can use the link element media attribute as an alternative to the CSS @media selector Blog article and source files: http://bit.ly/1jS2ivp Audience: Those who are new to CSS Cascading Style Sheets for mobile development. Welcome to this segment in our series on using CSS media queries to create a mobile first, responsive design. Now we are ready to explore approaches for organizing your mobile first responsive design CSS. So far we placed all our CSS and the media queries into one HTML document. You might say we should use the HTML link tag to load external CSS files. You would point out this is how we share CSS across multiple HTML documents. And you are right! The approach we will demonstrate uses multiple separate CSS files. One file will contain the base CSS and one file for each targeted screen width. But do we still need the media query selectors? Media query selectors are just CSS. They will work the same in external CSS files. However the HTML link tag has a media attribute. Conveniently it uses the same media queries syntax as the CSS media selector. This how we are going to do our example. Now this is just one approach. You need to consider other possible approaches. So we will also sketch out basic organizational alternatives. Then investigate the performance criteria involved. This approach can work well for you. It reduces the length of CSS and organized the targets into separate files. But by adding four css file we have also exposed four http network requests. Network requests provide overhead that could impact timing. For light weight traffic requirements this should not be significant. If it is a problem consider some alternatives. The obvious approach is to use one external css file. In that approach place the same css we had in the style tag into that file. Another approach is to have two css files. One for the base and one for the screen width changes. Then attach this after the base css file without the html link tag media attribute. The media selectors in the file will do the detections. In the beginning of our series we learned about other media query tests. For example we could test for screen resolution or orientation. Your design requirements increase when targeting particular design features. This can result in more media queries for the same target minimum widths. In that case you may consider our approach in the example we completed. The first css file is for smart phone widths. Second for tablet widths. The last for laptops and desktops. Each represents the base css for that target minimum width. Then within that target minimum width group you can add additional media queries targeting special cases. Such as a different pixel density image for a retina device versus a legacy device. You just add css media selectors within the css file for those special circumstances.
Html code for embedding videos on your blog
Text Comments (3)
Markku Arimo (1 year ago)
Thank you Lon! These is exactly the video I needed to see to help me with my .css learning! Very easy to understand and great explanations to substantiate your claims (with alternatives approaches to boot!)
Tim Curtin (1 year ago)
You teaching style is like telling your audience an inside joke. And you go way too fast in my opinion. Just saying. You might want to go in small chunks with the @media tutorial.
Betha Aqua (4 years ago)
I love your video sir, Thank you so much

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.