Friday, August 6, 2021
If you use media queries in CSS you can target a specific media with a stylesheet. It is defined by the media attribute in the link tag.
The possible media values are the following:
The possible media values are the following:
- all - all presentation media
- print - used for display print and print preview
- screen - all screens that uses the browser user agents
Here are a few examples:
<link type="text/css" href="print_media.css" media="print">
<link type="text/css" href="style.css" media="all">
<link type="text/css" href="screen_media.css" media="screen">
Or you can have multiple media types like this
<link type="text/css" href="screen_media.css" media="screen,print">
If you want to do it inline you can use by typing in the following:
<style type="text/css" media="screen">h1 {color:red;}</style>
Inside the stylesheets itself the media blocks has a @ prefix in front of it like so, you can have as many as you want.
@media all {
h1 {color:red;}
}
@media screen,print{
h2 {color: black;}
}
The cool thing about media queries is that you can apply some simple logic to the application of it for instance let's say you only want to use the style only if the screen meets a certain requirement you can say
@media all and (min-resolution: 300dpi) { }
@media screen not (orientation: landscape) {}
You can also use media queries to make older browsers ignore your new styles by using the @import directive.
Let's say you have styles.css stylesheet, but you also have the new styles in the new_styles.css file. You only want to apply the stylesheet new_styles.css in browsers that understands media queries. So in the styles.css stylesheet you have have the first line be @import url(new_styles.ccss) only all only browsers that understands media queries will apply the stylesheet while the old browsers will ignore it.
The other queries you can use which is similar to media queries are feature queries. As the name implies a feature querie apply a style only if the user agent supports the feature.
To implement a feature querie you would do something like this, if you want a block of style to only be applied if the grid layout is supported.
@supports (display:grid){}
You can also combine a support querie and a media querie, like so
@supports (display:flex){
@media screen { }
}
You can also use the and and not condition in feature queries as well, there's even an or
@supports (color: red) and (display:flex) or (display:grid) { }
Previous: CSS: Linking to An External Stylesheet With the link Tag and The @import Directive
Next: The ID And Class Selectors in CSS
Next: The ID And Class Selectors in CSS
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Thank you for sharing the post.
ReplyDeleteUSA Apostille
PG SOFT https://www.softswiss.com/game-providers/pg-soft/ is a world-class digital mobile games company. Pocket Games Software provide bespoke gaming solutions on iOS
ReplyDeleteFuture Line Service Corporation assists in putting your company on the correct track and concentrating your team on what really matters. It is one of the leading PRO Services Agency and Translation centre based in Qatar.
ReplyDeletehttps://futurelineqatar.com/
Our professional family visa services at Smart Voyage Migration increase your chances of re-joining with family members who are living in the USA, UK, Canada, Australia, New Zealand, Europe, and other nations. https://smartvoyagemigration.com/qatar/family-visa/
ReplyDeleteMove Leaders was established in 2019 locally in Qatar with experienced hands having more than 25 years of experience in relocation and freight forwarding industry. Currently Marine Leaders is one of the well-known professional global relocation companies Qatar in the logistics industry across the world. Move leaders
ReplyDeleteOffering one amongst the best legal translation services in Qatar, the terminologies used by different legal systems around the world are familiar to our team of carefully chosen legal translation experts. Futureline
ReplyDeletegreat post
ReplyDeletehttps://smartvoyagemigration.com/qatar/family-visa/
Great share https://www.bluelinkservices.qa/
ReplyDelete