The Most Used Responsive Breakpoints in 2017 Of Mine. CSS3 Media Queries? Device width? Screen Sizes? The rapid development of web design and electronic devices in this years which.
Example
Change the background color of the <body> element to 'lightblue' when the browser window is 600px wide or less:
@media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
Try it Yourself »body {
background-color: lightblue;
}
}
More 'Try it Yourself' examples below.
Definition and Usage
The
@media
rule is used in media queries to apply different styles for different media types/devices.Media queries can be used to check many things, such as:
- width and height of the viewport
- width and height of the device
- orientation (is the tablet/phone in landscape or portrait mode?)
- resolution
Using media queries are a popular technique for delivering a tailored style sheet (responsive web design) to desktops, laptops, tablets, and mobile phones.
You can also use media queries to specify that certain styles are only for printed documents or for screen readers (mediatype: print, screen, or speech).
In addition to media types, there are also media features. Media features provide more specific details to media queries, by allowing to test for a specific feature of the user agent or display device. For example, you can apply styles to only those screens that are greater, or smaller, than a certain width.
Browser Support
The numbers in the table specifies the first browser version that fully supports the @media rule.
CSS Syntax
@media not|only mediatype and (mediafeature and|or|not mediafeature) {
CSS-Code;
}
CSS-Code;
}
meaning of the not, only and and keywords:
not: The not keyword reverts the meaning of an entire media query.
only: The only keyword prevents older browsers that do not support media queries with media features from applying the specified styles. It has no effect on modern browsers.
and: The and keyword combines a media feature with a media type or other media features.
They are all optional. However, if you use not or only, you must also specify a media type.
You can also have different stylesheets for different media, like this:
<link media='screen and (min-width: 900px)' href='widescreen.css'>
<link media='screen and (max-width: 600px)' href='smallscreen.css'>
....
<link media='screen and (max-width: 600px)' href='smallscreen.css'>
....
Media Types
Value | Description |
---|---|
all | Default. Used for all media type devices |
Used for printers | |
screen | Used for computer screens, tablets, smart-phones etc. |
speech | Used for screenreaders that 'reads' the page out loud |
Media Features
Value | Description |
---|---|
any-hover | Does any available input mechanism allow the user to hover over elements? (added in Media Queries Level 4) |
any-pointer | Is any available input mechanism a pointing device, and if so, how accurate is it? (added in Media Queries Level 4) |
aspect-ratio | The ratio between the width and the height of the viewport |
color | The number of bits per color component for the output device |
color-gamut | The approximate range of colors that are supported by the user agent and output device (added in Media Queries Level 4) |
color-index | The number of colors the device can display |
grid | Whether the device is a grid or bitmap |
height | The viewport height |
hover | Does the primary input mechanism allow the user to hover over elements? (added in Media Queries Level 4) |
inverted-colors | Is the browser or underlying OS inverting colors? (added in Media Queries Level 4) |
light-level | Current ambient light level (added in Media Queries Level 4) |
max-aspect-ratio | The maximum ratio between the width and the height of the display area |
max-color | The maximum number of bits per color component for the output device |
max-color-index | The maximum number of colors the device can display |
max-height | The maximum height of the display area, such as a browser window |
max-monochrome | The maximum number of bits per 'color' on a monochrome (greyscale) device |
max-resolution | The maximum resolution of the device, using dpi or dpcm |
max-width | The maximum width of the display area, such as a browser window |
min-aspect-ratio | The minimum ratio between the width and the height of the display area |
min-color | The minimum number of bits per color component for the output device |
min-color-index | The minimum number of colors the device can display |
min-height | The minimum height of the display area, such as a browser window |
min-monochrome | The minimum number of bits per 'color' on a monochrome (greyscale) device |
min-resolution | The minimum resolution of the device, using dpi or dpcm |
min-width | The minimum width of the display area, such as a browser window |
monochrome | The number of bits per 'color' on a monochrome (greyscale) device |
orientation | The orientation of the viewport (landscape or portrait mode) |
overflow-block | How does the output device handle content that overflows the viewport along the block axis (added in Media Queries Level 4) |
overflow-inline | Can content that overflows the viewport along the inline axis be scrolled (added in Media Queries Level 4) |
pointer | Is the primary input mechanism a pointing device, and if so, how accurate is it? (added in Media Queries Level 4) |
resolution | The resolution of the output device, using dpi or dpcm |
scan | The scanning process of the output device |
scripting | Is scripting (e.g. JavaScript) available? (added in Media Queries Level 4) |
update | How quickly can the output device modify the appearance of the content (added in Media Queries Level 4) |
width | The viewport width |
More Examples
Example
Hide an element when the browser's width is 600px wide or less:
@media screen and (max-width: 600px) {
div.example {
display: none;
}
}
Try it Yourself »div.example {
display: none;
}
}
Example
Use mediaqueries to set the background-color to lavender if the viewport is 800 pixels wide or wider, to lightgreen if the viewport is between 400 and 799 pixels wide. If the viewport is smaller than 400 pixels, the background-color is lightblue:
body {
background-color: lightblue;
}
@media screen and (min-width: 400px) {
body {
background-color: lightgreen;
}
}
@media screen and (min-width: 800px) {
body {
background-color: lavender;
}
}
Try it Yourself »background-color: lightblue;
}
@media screen and (min-width: 400px) {
body {
background-color: lightgreen;
}
}
@media screen and (min-width: 800px) {
body {
background-color: lavender;
}
}
Example
Create a responsive navigation menu (displayed horizontally on large screens and vertically on small screens):
@media screen and (max-width: 600px) {
.topnav a {
float: none;
width: 100%;
}
}
Try it Yourself ».topnav a {
float: none;
width: 100%;
}
}
Example
Use media queries to create a responsive column layout:
/* On screens that are 992px wide or less, go from four columns to two columns */
@media screen and (max-width: 992px) {
.column {
width: 50%;
}
}
/* On screens that are 600px wide or less, make the columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
Try it Yourself »@media screen and (max-width: 992px) {
.column {
width: 50%;
}
}
/* On screens that are 600px wide or less, make the columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
Example
Use media queries to create a responsive website:
Try it Yourself »Example
Media queries can also be used to change layout of a page depending on the orientation of the browser. You can have a set of CSS properties that will only apply when the browser window is wider than its height, a so called 'Landscape' orientation.
Use a lightblue background color if the orientation is in landscape mode:
@media only screen and (orientation: landscape) {
body {
background-color: lightblue;
}
}
Try it Yourself »body {
background-color: lightblue;
}
}
Example
Use mediaqueries to set the text color to green when the document is displayed on the screen, and to black when it is printed:
@media screen {
body {
color: green;
}
}
@media print {
body {
color: black;
}
}
Try it Yourself »body {
color: green;
}
}
@media print {
body {
color: black;
}
}
Example
Comma separated list: add an additional media query to an already existing one, using a comma (this will behave like an OR operator):
/* When the width is between 600px and 900px OR above 1100px - change the appearance of <div> */
@media screen and (max-width: 900px) and (min-width: 600px), (min-width: 1100px) {
div.example {
font-size: 50px;
padding: 50px;
border: 8px solid black;
background: yellow;
}
}
Try it Yourself »@media screen and (max-width: 900px) and (min-width: 600px), (min-width: 1100px) {
div.example {
font-size: 50px;
padding: 50px;
border: 8px solid black;
background: yellow;
}
}
Related Pages
CSS Tutorial: CSS Media Queries
CSS Tutorial: CSS Media Queries Examples
RWD Tutorial: Responsive Web Design with Media Queries
JavaScript Tutorial: The window.matchMedia() method
Image Caption Hover Demo with Hover Effects Demo 3 – WebCodingPlace. Accordion tabs Design Inspiration - HTML & CSS Snippets ~ Page 2 of 2 ~ CodeMyUI. Favicon.ico multi-résolution, icônes de favoris - favicon.fr. Blueprint: On-Scroll Animated Header. Blueprint: Horizontal Drop-Down Menu. Blueprint: Responsive Full Width Tabs. 100% width tabbed content with some example media queries for smaller screens.
View demo Download source A full width tab component with some example media queries for adjusting the icons of the tabs and the content layout. The main idea is to show only icons for the mobile view and allow the text to appear when there’s enough space. The content columns and the containing media boxes have three different layouts. The food shapes in the content images are from PsdBlast. The HTML. Horizontal Slide Out Menu. A horizontal slide out menu with a grid-like thumbnail layout for the submenu.
With media query examples for smaller devices. View demo Download source A simple, horizontal slide out menu with a grid-like thumbnail layout for the submenu. The menu slides out from the top when a main menu item is clicked and the sub-items fade in. When clicking on another item, the height of the submenu will adjust and the content will fade in and out while switching. Some media query examples show how to make the menu responsive and change the view to a touch-friendly vertically stacked navigation.Nested Accordion. A simple, nestable accordion with some examples of nesting levels and a media query.
View demo Download source A simple accordion that allows for a nested structure. The style comes with some examples of how to style three levels and how to add a media query for decreasing the size on smaller screens.Elastic Content Slider. A fluid content slider that will adjust in width and height depending on the size of its parent.
View demo Download source This Blueprint is a simple jQuery content slider. It has a sliding area for content and a tab-like navigation at the bottom. The slider is fluid, meaning that it will adjust to the parent’s container width and height. A couple of media queries show how to minimalise the look by just leaving icons for the navigation when the screen is very small. Note that we don’t show vendor prefixes here, but you’ll find them in the files. The HTML. Production Company. Hover.css - A collection of CSS3 powered hover effects.
All Hover.css effects make use of a single element (with the help of some pseudo-elements where necessary), are self contained so you can easily copy and paste them, and come in CSS, Sass, and LESS flavours.
Many effects use CSS3 features such as transitions, transforms and animations. Old browsers that don't support these features may need some extra attention to be certain a fallback hover effect is still in place. Licenses. Centrer en CSS, un guide complet. Le centrage en CSS est souvent un véritable casse-tête, car il existe plusieurs techniques différentes selon les cas d'utilisation.
Flexbox, guide complet. Le module Flexbox Layout fournit une façon plus efficace de disposer, aligner et distribuer l'espace entre les éléments de votre page. 4 riches articles de Chris Coyier sont réunis ici.
Par Chris Coyier NdT : Ce tutoriel est la réunion de quatre articles de Chris Coyier formant une introduction à Flexbox. Vous pouvez ensuite consulter tous les articles sur Flexbox traduits dans la Cascade notamment les exemples concrets d'implémentation et les astuces techniques. Le module CSS3 Flexbox Layout fournit une façon plus efficace de disposer, aligner et distribuer l'espace entre les items d'un container, même lorsque leurs dimensions sont inconnues et/ou dynamiques - d'où le terme 'flex'. L'idée principale est de donner à un élément contenant (container) la possibilité de changer les largeur et hauteur des éléments contenus (items), afin de remplir au mieux l'espace disponible, et s'adapter à tous les devices et toutes les tailles d'écrans.
Download Free Adobe Muse Tabs Color Box. Download Adobe Muse Classic Tabbed Box Widget. Home. Adobe Muse Tabs - Adobe Muse Templates. W3Schools Online Web Tutorials. Make a DIV stick when you scroll. I’ve seen this method used a lot around the web and I’ve recently been working on a website where I wanted to incorporate it.
After finding zero results in about a minute of research, I thought this would be a neat topic to write a post about. So my main concept here is to have a sidebar that would stick to the top of the page once the window was about to pass it by while scrolling. This could be used for dozens of reasons. Perhaps you want to ensure your advertisements are being shown the maximum amount of time possible; or maybe you want to offer your visitors an area of quick-links so they wouldn’t have to scroll to the top of the page to navigate somewhere else. The site I’m working on is e commerce, so it will be an area to up-sell other products relative to the page the user is viewing. In the code below, I have two DIVs floating that represent the main content area and the sidebar.60+ Free jQuery Image Slider & Slideshow Plugins - freshDesignweb. CSS3 Hover Effect Transitions, Transformations, Animations. This post is all about CSS3 effect examples.
We’re going to find out more about hover effect transitions, transformations and animations. All of them come with visual examples. I’ve also included the source code. Feel free to use and adjust the code provided on whatever you are planning to do. CSS3 is great. Vendor prefixes: Everything you need to know!
Related: HTML/CSS - Webdesign Tools - Web Developer - web design - HTML - CSS - For webpage - FrontEnd - css - CSS - WEB DESIGN - Code & Development - Affichage - SCSS - Test + astuce + semblables - CSS - Learning resources - CSS - Adornments - shimadzu - Hover.css - A collection of CSS3 powered hover effects - W3Schools Online Web Tutorials - Codes and Ciphers - QR Codes - Car Rental • Coupons • Codes • reviews #travel - Codes and Conspiracies - QR Codes for Education - mrf_crf_codes - codes of conduct in open source projects - Codes of Conduct - Bargains And Codes - Callsign Database by QRZ.COM - Error 404 (Not Found)!!1 - QuickMark | an easy-to-use barcode scanner for iPhone and Android - RadioReference.com - Scanner Frequencies and Radio Frequency Reference - Binary to Text (ASCII) Conversion - Freeware Hex Editor XVI32 - i-nigma create barcodes QR DataMatrix - QR Code Classroom Implementation Guide - Cipher Tools - Sharky's Vigenere Cipher - iLearn Technology » Blog Archive » Make your own QR Code Scavenger Hunt! - QRpedia - Language-detecting & mobile-friendly Wikipedia QR codes - Education - Enterprise