Media Queries left blank - could this cause problems? - css

Im curious about leaving the #media definitions empty in my stylesheet and if this could cause some problems rendering the page?
I only want to include those queries for presentation - to show them, that it's possible to go responsive with the queries enabled.
here is my css:
/*************************************************************************************************/
/* Media Queries - Responsive Layout Definitionen */
/*************************************************************************************************/
/* Smartphones (Portrait und Landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (Portrait und Landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops und Laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Große Screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
/*************************************************************************************************/
/* ==================== */
/*************************************************************************************************/

Empty #media rules have no effect on page rendering or stylesheet parsing. Just make sure you open and close them properly.
If you need the details, the relevant portions of the grammar can be found in the spec. But in a nutshell, a #media rule may have zero or more rules nested within, which means it may be empty with no issues.

Related

Floated Elements: Different Max-Widths on Different Screens

The main functionality of my site (http://kawaiiface.net) is stringent upon floats and max-widths working well. My sidebar slots are float: left; and float: right; , and my content buttons are margins: auto;. Everything positions itself in relation to one another responsively on desktop screen sizes -- but on mobile, the sidebars appear above the content.
In anticipation of the algo update, I've gone ahead and added responsive containers to everything: my sidebars run a max-width: 160px; with width: 100%; to 1. keep them in the spot they should be and 2. allow them to be responsive on smaller screens. This has caused an issue, though -- where the max-width allows my containers to fit well and provide a proper UE on desktop, they prevent the slots from expanding enough to fill the whole screen on mobile!
How can I remove my max-width parameter when my left-floated element is in its own block (aka above everything else on smaller screens)? Here is an image to help.
Thanks so much!!
An example of using Media queries
Helpful website: https://css-tricks.com/css-media-queries/
Example:
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles for smartphones here */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles for smartphones here */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles for smartphones here */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles for ipad here */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles for ipad landscape here */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles for upad here */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* desktops and laptops style goes here */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles for large screen here *?
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {}
Add this to your css at the top, inside each {} you can change an element depending on the dimensions of the devices width. There are a wide range of varieties depending on the devices you're targeting but this is the broad spectrum.

CSS media queries to hide and show page elements .

I'm kind of new to coding with media queries, and I think I have painted myself into a corner, using too many media queries (and probably in the wrong way).
What I want to do is to hide some page elements when the width of the screen or device is smaller than 481px. So in the screenshot below, you might be able to see the couple of lines of text in the upper right corner.
My problem has to do with the media queries that I've used. I am at wit's end to figure out (1) why the page elements (those two lines of text in the upper right corner) are not disappearing when the page gets smaller than 481px OR (2) why they do not appear in any larger screen/device sizes when I do manage to get the page elements to disappear.
Here is the piece of CSS code that seems to cause some issues:
/* Smartphones (landscape) ----------- */
#media only screen and (min-width : 321px){
/* Hiding elements for this device * * * * * * * * * * * * * */
/*
.poweredBy{
display: none;
}
*/
}
With this code commented out, those two lines of text won't disappear until the window (device?) width is somewhere around 320px.
Here is the entire CSS:
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
.poweredBy{
display: none;
}
}
/* Smartphones (landscape) ----------- */
#media only screen and (min-width : 321px){
.poweredBy{
display: none;
}
}
/* Smartphones (portrait) ----------- */
#media only screen and (max-width : 320px) {
.poweredBy{
display: none;
}
}
/* iPhone 4 ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {}
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {}
/* iPads (portrait and landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {}
/* iPads (landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {}
/* iPads (portrait) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {}
/* iPad 3 ---------------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {}
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {}
/* Desktops and laptops ----------- */
#media only screen and (min-width : 1224px) {}
/* 960px layouts ----------- */
#media only screen and (min-width : 960px){}
/* Large screens ----------- */
#media only screen and (min-width : 1824px) {}
I am using GroundworkCSS underneath, but I have added a few media queries myself -- that was most likely not an enlightened act on my behalf. So if anyone could point me in the right direction, I would be most grateful. Thanks.
You have way to many media queries, the most you should have is three one for tablet, tablet landscape and mobile. Typically like this,
CSS
/** Mobile **/
#media only screen and (max-width: 767px), only screen and (max-device-width: 767px) {
}
/** Tablet **/
#media only screen and (min-width : 768px) and (max-width : 1024px) {
}
/** Tablet (landscape) **/
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
}
The css code for portrait and landscape:
#media screen and (orientation:portrait) {
/* Style for portrait mode goes here */
}
#media screen and (orientation:landscape) {
/* Style for landscape mode goes here */
}
Or, as written by Mitch Layzell,
you can use this:
#media only screen and (max-width: 767px), only screen and (max-device-width: 767px) {
/** Mobile **/
}
#media only screen and (min-width : 768px) and (max-width : 1024px) {
}
/** Tablet (landscape) **/
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/** Tablet **/
}
If you want you can insert "(orientation : landscape)" and "max-width" or "max-width-device" together.

How to change the css style for phone and desktop?

I've got a block of html, let's call it a tile. When the screen is wide we lay down tiles horizontally in rows. But when the screen is less than two tiles wide we lay them down the page.
Inside the tiles are an image and some text. When the tiles are going across the page the image should show above the text. But when there is only one tile in a row the image should show to the left of the text.
Perhaps you're still with me. I'm trying to work out how to use the same html for both layouts and apply the left/top positioning of the image purely with css. The tile html looks like this:
<li class="car-item">
<img src="{{car_image}}" class="img-rounded">
<h3>{{name}}</h3>
<ul>
<li class="ico-body">{{body}}</li>
<li class="ico-petrol">{{cylinder}}</li>
<li class="ico-transmission">{{transmission}}</li>
</ul>
</li>
The sass/css has gone through a number of variations. I've been trying to use visible-phone class but my attempts always wind up needing to output two versions of the html, one with "visible-phone" class and another "hidden-phone" class. Is this really necessary?
Is it not possible to declare a default css class (for desktop) and an alternate which automatically applies to phone?
.visible-phone
height: none
margin-right: 10px
img
float: left
(#media?)
Here are the media queries of standard devices (from CSS-Tricks.com):
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
All of the areas that say /* Styles */ are where you would place the separate CSS components for the different devices you are supporting.
**PLEASE NOTE: this is a pretty convoluted media query sheet. I would normally delete the landscape stuff, and the iPhone media query takes care of most smartphones, so there's normally no need to have two separate ones for that. Here is what I usually use:
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
(and from Creating a mobile web page with different css style)

Bootstrap multiple resolution all layout inline media query CSS for responsive design including Android iphone and web asp.net

I have finished a website, it's working fine in browser now. I have been asked to make it compatible with Android, iPhone, iPad, Tablets,and web etc. I'm using bootstrap asp.net.
Now I'm trying and couldn't find any answer. I'm using these inline media queries
#media screen and (min-width:0px) and (max-width:320px){/*Any css will be defined here*/}
#media screen and (min-width:321px) and (max-width:480px){/*Any css will be defined here*/}
#media screen and (min-width:481px) and (max-width:540px){/*Any css will be defined here*/}
#media screen and (min-width:541px) and (max-width:775px){/*Any css will be defined here*/}
#media screen and (min-width:768px) and (max-width:783px){/*Any css will be defined here*/}
#media screen and (min-width:776px) and (max-width:1536px){/*Any css will be defined here*/}
#media screen and (min-width:1537px){/*Any css will be defined here*/}
But in some iPads the CSS is not applied. Now my question is, what's the standard resolution and orientation for #media which will cover all (Android, iPhone, tablets and Web etc) CSS?
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media only screen
and (-webkit-min-device-pixel-ratio : 1.5),
and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
That's what I use, and it works for almost everything.
After spending many hours I found this helpful. This is used by Bootstrap itself and I followed that. It will cover all the devices (Android, iPhone Tabs and web etc).
#media handheld, only screen and (max-width: 2200px)
{
/* Styles */
}
#media handheld, only screen and (max-width: 1200px)
{
/* Styles */
}
#media handheld, only screen and (max-width: 1024px)
{
/* Styles */
}
#media handheld, only screen and (max-width: 767px) {
/* Styles */
}
#media handheld, only screen and (max-width: 600px) {
/* Styles */
}
#media handheld, only screen and (max-width: 500px) {
/* Styles */
}
#media screen and (-webkit-min-device-pixel-ratio:0) {
/* Styles */
}

CSS3 media queries to target specific device

I have my wordpress theme with basic CCS, Now I want to make this design responsive for most used device layout's noted below.And I want to target all apple devices in landscape as well as in portrait mode:-
blackberry(320x240),
iphone3 (320x480),
iphone4 (640x960),
iphone5 (640x1136),
ipad (1024x768),
large desktop screen above 1280.
How can I write my CSS stylesheet using CSS3 media queries to target responsive devices?
http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
Here is just a starter. You can read more abour media-queries and other resonsive design stuff on that blog.
Here is a sample of css code:
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}

Resources