Floated Elements: Different Max-Widths on Different Screens - css

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.

Related

Media Queries left blank - could this cause problems?

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.

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 Make iPhone scaling the same as iPad.

My site collapses nicely for the iPad version but once it collapses for iPhone it is a mess. I would prefer just to keep the iPad version for iPhone as well.
I know I have to override /* Landscape phones and down */
#media (max-width: 480px) { ... }
but do I have to override each individual param? Can't I simply tell it somehow "don't collapse below 768px"
I am using a CDN hosted bootstrap and doing custom overrides in my css.
This are the suggested medias:
/* 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 */
}
As you can see, here I'm using device-width instead of width.
If what you want is to use same style in iPad and iPhone and there are not constrains between 480px y 768px, you can simply:
#media only screen and (min-device-width : 320px) and (max-device-width : 1024px) {
/* Styles */
}
Hope this helps!

Common CSS Media Queries Break Points [duplicate]

This question already has answers here:
Common breakpoints for media queries on a responsive site
(5 answers)
Closed 3 years ago.
I am working on a Responsive Web Site with CSS Media Queries.
Is the following a good organization for devices?
Phone, Ipad (Landscape & Portrait), Desktop and Laptop, Large Screen
What are the common media queries break-point values?
I am planning to use the following breakpoints:
320: Smartphone Portrait
481: Smartphone Landscape
641 or 768 ???: IPad Portrait ???
961: IPad Landscape / Small Laptop ???
1025: Desktop and Laptop
1281: Wide Screen
What do you think? I have a few doubts as ??? points.
Rather than try to target #media rules at specific devices, it is arguably more practical to base them on your particular layout instead. That is, gradually narrow your desktop browser window and observe the natural breakpoints for your content. It's different for every site. As long as the design flows well at each browser width, it should work pretty reliably on any screen size (and there are lots and lots of them out there.)
I've been using:
#media only screen and (min-width: 768px) {
/* tablets and desktop */
}
#media only screen and (max-width: 767px) {
/* phones */
}
#media only screen and (max-width: 767px) and (orientation: portrait) {
/* portrait phones */
}
It keeps things relatively simple and allows you to do something a bit different for phones in portrait mode (a lot of the time I find myself having to change various elements for them).
I'm using 4 break points but as ralph.m said each site is unique.
You should experiment. There are no magic breakpoints due to so many devices, screens, and resolutions.
Here is what I use as a template.
I'm checking the website for each breakpoint on different mobile devices and updating CSS for each element (ul, div, etc.) not displaying correctly for that breakpoint.
So far that was working on multiple responsive websites I've made.
/* SMARTPHONES PORTRAIT */
#media only screen and (min-width: 300px) {
}
/* SMARTPHONES LANDSCAPE */
#media only screen and (min-width: 480px) {
}
/* TABLETS PORTRAIT */
#media only screen and (min-width: 768px) {
}
/* TABLET LANDSCAPE / DESKTOP */
#media only screen and (min-width: 1024px) {
}
UPDATE
As per September 2015, I'm using a better one. I find out that these media queries breakpoints match many more devices and desktop screen resolutions.
Having all CSS for desktop on style.css
All media queries on responsive.css: all CSS for responsive menu + media break points
#media only screen and (min-width: 320px) and (max-width: 479px){ ... }
#media only screen and (min-width: 480px) and (max-width: 767px){ ... }
#media only screen and (min-width: 768px) and (max-width: 991px){ ... }
#media only screen and (min-width: 992px){ ... }
Update 2019: As per Hugo comment below, I removed max-width 1999px because of the new very wide screens.
This is from css-tricks link
/* 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 */
}
I can tell you I am using just a single breakpoint at 768 - that is min-width: 768px to serve tablets and desktops, and max-width: 767px to serve phones.
I haven't looked back since. It makes the responsive development easy and not a chore, and provides a reasonable experience on all devices at minimal cost to development time without the need to fear a new Android device with a new resolution you haven't factored in.
Media Queries for Standard Devices
In General for Mobile, Tablets, Desktop and Large Screens
1. Mobiles
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
2. Tablets
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
3. Desktops & laptops
#media only screen
and (min-width : 1224px) {
/* Styles */
}
4. Larger Screens
#media only screen
and (min-width : 1824px) {
/* Styles */
}
In Detail including landscape and portrait
/* 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 */
}
/* Tablets, iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* Tablets, iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* Tablets, 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 */
}
Reference
Consider using twitter bootstrap's break points.
with such a massive adoption rate you should be safe...
#media only screen and (min-width : 320px) and (max-width : 480px) {/*--- Mobile portrait ---*/}
#media only screen and (min-width : 480px) and (max-width : 595px) {/*--- Mobile landscape ---*/}
#media only screen and (min-width : 595px) and (max-width : 690px) {/*--- Small tablet portrait ---*/}
#media only screen and (min-width : 690px) and (max-width : 800px) {/*--- Tablet portrait ---*/}
#media only screen and (min-width : 800px) and (max-width : 1024px) {/*--- Small tablet landscape ---*/}
#media only screen and (min-width : 1024px) and (max-width : 1224px) {/*--- Tablet landscape --- */}
If you go to your google analytics you can see which screen resolutions your visitors to the website use:
Audience > Technology > Browser & OS > Screen Resolution ( in the menu above the stats)
My site gets about 5,000 visitors a month and the dimensions used for the free version of responsinator.com are pretty accurate summary of my visitors' screen resolutions.
This could save you from needing to be too perfectionistic.
I always use Desktop first, mobile first doesn't have highest priority does it? IE< 8 will show mobile css..
normal css here:
#media screen and (max-width: 768px) {}
#media screen and (max-width: 480px) {}
sometimes some custom sizes. I don't like bootstrap etc.
Instead of using pixels should use em or percentage as it is more adaptive and fluid, better not target devices target your content:
HTML5 rockrs read, mobile first
Keep your code clean and stylesheets logically separated per screen 'media' type config...
1) Using himansu's answer from above as a reference: Common CSS Media Queries Break Points
AND
2) https://www.w3schools.com/css/css3_mediaqueries.asp
your answer would be:
<link rel="stylesheet" media="#media only screen and (min-width : 320px) and (max-width : 480px)" href="mobilePortrait.css">
<link rel="stylesheet" media="#media only screen and (min-width : 481px) and (max-width : 595px)" href="mobileLandscape.css">
Your break points look really good. I've tried 768px on Samsung tablets and it goes beyond that, so I really like the 961px.
You don't necessarily need all of them if you use responsive CSS techniques, like % width/max-width for blocks and images (text as well).

What are good resolution values to use with media queries?

Recently I've been playing around with CSS Media Queries because it's a great way to make my website adapt to various screen sizes. I am planning to implement them into the live version.
My question is: Are there any recommended resolution values at which the layout changes?
See this article for a template '320 and Up' - by Andy Clarke, it's used by many developers and designers: http://www.stuffandnonsense.co.uk/blog/about/this_is_the_new_320_and_up
If you scroll down to the media queries section you'll see they use five CSS3 Media Query increments (480, 600, 768, 992 and 1382px). Typically I stick to just 4 (480, 600, 768, 1024).
To explain the ranges:
min-width: 480px: Will target mobile devices in landscape mode and up
min-width: 600px: Targets tablets in portrait mode and up
min-width: 768px: Targets tablets in landscape mode and up
min-width: 1024px: Targets the desktop view
And typically I will have my mobile portrait view CSS at the very beginning (hence the term "320 and up").
I would just like to add to Suvi's answer.
Adaptive Design applies media queries to targeted resolutions however with Responsive Design you are free to add the breakpoints wherever you feel is necessary.
There is no rule as to how many breakpoints a page should have, but one should be added wherever the layout breaks. The aim is to make sure the design and content flows nicely regardless of the width of the viewport.
I think this post provides a good overview:
http://www.williamwalker.me/blog/an-introduction-to-responsive-design.html
Try this one with retina display
/* 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 */
}
Hope you are fine
I wrote this less solution:
/* screens range */
#screen-s-max: 20em; /* 320px */
#screen-min: 20.063em; /* 321px */
#screen-max: 40em; /* 640px */
#screen-m-min: 40.063em; /* 641px */
#screen-m-max: 64em; /* 1024px */
#screen-l-min: 64.063em; /* 1025px */
#screen-l-max: 90em; /* 1440px */
#screen-xl-min: 90.063em; /* 1441px */
#screen-xl-max: 120em; /* 1920px */
#screen-xxl-min: 120.063em; /* 1921px */
/*
0----- smallmobile -----320----- mobile -----640----- tablet -----1024----- notebook -----1440----- desktop -----1920----- wide
*/
#onlyScreen: ~"only screen";
#smallmobile: ~"(max-width: #{screen-s-max})";
#mobile: ~"(min-width: #{screen-s-max}) and (max-width: #{screen-max})";
#tablet: ~"(min-width: #{screen-m-min}) and (max-width: #{screen-m-max})";
#notebook: ~"(min-width: #{screen-l-min}) and (max-width: #{screen-l-max})";
#desktop: ~"(min-width: #{screen-xl-min}) and (max-width: #{screen-xl-max})";
#wide: ~"(min-width: #{screen-xxl-min})";
#portrait: ~"(orientation:portrait)";
#landscape: ~"(orientation:landscape)";
#highdensity: ~"only screen and (-webkit-min-device-pixel-ratio: 1.5)",
~"only screen and (min--moz-device-pixel-ratio: 1.5)",
~"only screen and (-o-min-device-pixel-ratio: 3/2)",
~"only screen and (min-device-pixel-ratio: 1.5)";
#mobile-and-more: ~"(min-width: #{screen-min})";
#tablet-and-more: ~"(min-width: #{screen-m-min})";
#notebook-and-more: ~"(min-width: #{screen-l-min})";
#desktop-and-more: ~"(min-width: #{screen-xl-min})";
/*
syntax example
#media #onlyScreen and #tablet and #portrait , #notebook and #landscape, #mobile and #landscape{
body{
opacity: 0.8;
}
}
*/
As shown in syntax example you can combine all these less variables and obtain complex media query. Use "and" for AND logic operator and comma for OR. You can combine different screen resolutions, device orientation (landscape/portrait) and retina or not devices.
This code is also easy configurable cause you can edit/add/remove screens range values to manage different screen resolutions.

Resources