How do I build a website at two screen widths: 375px and 1024px? the website need not respond to widths between the two.
#media only screen and (min-width : 375px) and (max-width : 1024px)
As far as I know this tag media work between 375 and 1024. Perhaps using breakpoint is the right approach. Any suggestion?
It is always best to design your CSS mobile-first, which means that your CSS file looks a little like this:
CSS:
// Basic CSS
div {
height: 200px;
width: 200px;
background-color: yellow;
}
#media screen and (min-width: 375px) {
div {
height: 150px;
}
}
#media screen and (min-width: 1024px) {
div {
height: 100px;
background-color: red;
}
This way you have a div that renders in three different ways on your breakpoints
0 - 374px it's a square of 200x200 pixels with a yellow background
375px - 1023px it's a rectangle of 150x200 pixels with a yellow background
1024px and up it's a rectangle of 100x200 pixels with a red background
This way you don't repeat yourself too much, your code stays clean and you only override what is necessary.
I am giving media queries for all devices with portrait mode also . I am given the media query CSS using breakpoint also. Use this media query for the better use and also the portrait devices include in this answer:
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
#media (min-width: 1281px) {
//CSS
}
/*
##Device = Laptops, Desktops
##Screen = B/w 1025px to 1280px
*/
#media (min-width: 1025px) and (max-width: 1280px) {
//CSS
}
/*
##Device = Tablets, Ipads (portrait)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) {
//CSS
}
/*
##Device = Tablets, Ipads (landscape)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
//CSS
}
/*
##Device = Low Resolution Tablets, Mobiles (Landscape)
##Screen = B/w 481px to 767px
*/
#media (min-width: 481px) and (max-width: 767px) {
//CSS
}
/*
##Device = Most of the Smartphones Mobiles (Portrait)
##Screen = B/w 320px to 479px
*/
#media (min-width: 320px) and (max-width: 480px) {
//CSS
}
Related
Ive just uploaded my first site for testing and already found that on a mobile device it isnt doing what I wanted? sorry this is my first site and first question so if you need any more information please ask. The site is nixoncreations.com . The images in desktop should be in a row of 3 , ive added
#media screen and (max-width: 1000px) {
.portfolio-items-wrapper {
display: grid;
grid-template-columns: 1fr ;}
It works on my laptop screen but not my phone, any advice and help would be much appreciated
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
#media (min-width: 1281px) {
/* CSS */
}
/*
##Device = Laptops, Desktops
##Screen = B/w 1025px to 1280px
*/
#media (min-width: 1025px) and (max-width: 1280px) {
/* CSS */
}
/*
##Device = Tablets, Ipads (portrait)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) {
/* CSS */
}
/*
##Device = Tablets, Ipads (landscape)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
/* CSS */
}
/*
##Device = Low Resolution Tablets, Mobiles (Landscape)
##Screen = B/w 481px to 767px
*/
#media (min-width: 481px) and (max-width: 767px) {
/* CSS */
}
/*
##Device = Most of the Smartphones Mobiles (Portrait)
##Screen = B/w 320px to 479px
*/
#media (min-width: 320px) and (max-width: 480px) {
/* CSS */
}
Thank you for that I will use that in the future, still didnt work but I found out what it was. I forgot to add this, as I said I'm new and would love advice
<meta name="viewport" content="width=device-width, initial-scale=1.0">
I have media queries and for all devices, you can see it here, in CSS -
and here without all the elements...
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops */
#media (min-width: 80.0625em) {
......
}
/*
##Device = Laptops, Desktops
##Screen = B/w 1025px to 1280px */
#media (min-width: 64.0625em) and (max-width: 80em) {
............
}
/*
##Device = Tablets, Ipads (portrait)
##Screen = B/w 768px to 1024px */
#media only screen and (min-width: 48em)
and (max-width: 64em)
and (orientation: portrait) {
............................
}
/*
##Device = Tablets, Ipads (landscape)
##Screen = B/w 768px to 1023px
*/
#media (min-width: 48em) and (max-width: 64em) and (orientation: landscape) {
....................
}
/*
##Device = Low Resolution Tablets, Mobiles (Landscape)
##Screen = B/w 481px to 767px
*/
#media only screen and (min-width: 41.75em) and (max-width: 47.9375em) {
..............
}
/* für iPhone 6/7/8 766,4px x 375px */
#media only screen and (max-width: 47.9em)
and (min-width: 23.4375em)
and (orientation: landscape) {
...............................
}
/* kleine smartphone Landscape 640px x 319px kleine als Galaxy S5 */
#media only screen and (max-width: 40em) and (orientation: landscape) {
..................................
}
/* iphone 5 und kleine 528px */
#media only screen and (max-width: 33em) and (orientation: landscape) {
......................
}
/* ich selb gebaut 767px x 481px
#media only screen and (max-width: 30.0625em) and (orientation: portrait) {
...................
}
/* iphone 5 galaxy S5 */
#media only screen and (max-width: 23em) and (orientation: portrait) {
.......................
}
My problem is with Samsung Galaxy off A 50 and Landscape, till A 40, landscape and portrait, working gut, but off A 50, only portrait working.
Can anyone help me and give me an idea how I can remedy this problem?
I found the solution for Media Query for Samsung Galaxy off A 50 landscape .
I add:
#media only screen and (max-width: 55.75em) {
.......................
}
betwixt
#media (min-width: 48em) and (max-width: 64em) and (orientation: landscape) {
....................
}
and
#media only screen and (min-width: 41.75em) and (max-width: 47.9375em) {
..............
}
I was at a shopping centre and locking many Smartphone, and the majority of them can see my website gut.... I think the best solution for this problem is making smaller the difference between Media Queries on max-width.
There are bootstrap 3 media breakpoints
/*========== Mobile First Method ==========*/
/* Custom, iPhone Retina */
#media only screen and (min-width : 320px) {
}
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px) {
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px) {
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
}
/*========== Non-Mobile First Method ==========*/
/* Large Devices, Wide Screens */
#media only screen and (max-width : 1200px) {
}
/* Medium Devices, Desktops */
#media only screen and (max-width : 992px) {
}
/* Small Devices, Tablets */
#media only screen and (max-width : 768px) {
}
/* Extra Small Devices, Phones */
#media only screen and (max-width : 480px) {
}
/* Custom, iPhone Retina */
#media only screen and (max-width : 320px) {
}
I just dont understand why in mobile first min-width and max-width in non-mobile described as equal. I mean for example min-width for tablets = 768px, so it means all widths > 768, and in max-width 768 for tablets too, but it means < 768px, it looks like range for tablets in mobile-first = 768-991px and in non-mobile 481-768
Bootstrap and in general all media queries usually define width breakpoints with ranges. In this case, in the css you showed, breakpoints with the same header comment are synonyms.
You can define better with the two options like this (for example):
/* Extra Small Devices, Phones */
#media only screen and (max-width: 480px) and (min-width: 321px) { }
You also can use another (and the posibility to concatenate) selectors to specify the screen position or other parameters. Here are some of this:
height
orientation
color-index
monochrome
resolution
scan
grid
I have looked at similar questions here and did not find a suitable answer, so forgive me that this question may appear at first to be a duplicate of others here.
My screen resolution is 1366px wide
I have default styles, and then several media queries at the end of the stylesheet, in the following order:
#media only screen and (max-width:1920px) {
}
#media only screen and (max-width:1680px), only screen and (max-device-width: 1680px) {
}
#media only screen and (max-width:1280px), only screen and (max-device-width: 1280px) {
}
#media only screen and (max-width:1024px), only screen and (max-device-width: 1024px) {
}
#media only screen and (max-width: 800px), only screen and (max-device-width: 800px) {
}
#media screen and (min-device-width: 768px) and (max-device-width: 1024px){
}
On my machine, the styles from the very first media query (max-width: 1920px) are being applied. When I inspect in Firebug, it gives me the line # coinciding with a declaration within that first media query.
This is happening across several browsers (Firefox, Chrome)
But, my viewport is just 1366px wide - so, I would expect either max-width:1280px or max-width:1680px to match, and not 1920px.
When I resize to 1024x768, or 800x600, the correct media query styles are applied.
What am I doing wrong?
I've looked for any missing bracket closures and found none. I've validated using the W3C CSS validator service, and checked as Correct, no errors found.
The issue is your logic.
Your first query states max-width: 1920px. Indeed, because your desktop is at 1366px, it is smaller than 1920px, so it is a valid query. Consider this a catch all after your 1680px.
I would suggest re-ordering and starting with smallest, most constraining queries first:
#media screen and (min-device-width: 768px) and (max-device-width: 1024px){
}
#media only screen and (max-width: 800px), only screen and (max-device-width: 800px) {
}
#media only screen and (max-width:1024px), only screen and (max-device-width: 1024px) {
}
#media only screen and (max-width:1280px), only screen and (max-device-width: 1280px) {
}
#media only screen and (max-width:1680px), only screen and (max-device-width: 1680px) {
}
#media only screen and (max-width:1920px) {
}
An even better approach would be to use min-width for all of your queries:
#media screen and (min-device-width: 768px) and (max-device-width: 1024px){
}
#media only screen and (min-width: 800px), only screen and (min-device-width: 800px) {
}
#media only screen and (min-width:1024px), only screen and (min-device-width: 1024px) {
}
#media only screen and (min-width:1280px), only screen and (min-device-width: 1280px) {
}
#media only screen and (min-width:1680px), only screen and (min-device-width: 1680px) {
}
#media only screen and (min-width:1920px) {
}
As a best practice, here is Bootstraps queries:
/*==================================================
= Bootstrap 3 Media Queries =
==================================================*/
/*========== Mobile First Method ==========*/
/* Custom, iPhone Retina */
#media only screen and (min-width : 320px) {
}
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px) {
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px) {
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
}
/*========== Non-Mobile First Method ==========*/
/* Large Devices, Wide Screens */
#media only screen and (max-width : 1200px) {
}
/* Medium Devices, Desktops */
#media only screen and (max-width : 992px) {
}
/* Small Devices, Tablets */
#media only screen and (max-width : 768px) {
}
/* Extra Small Devices, Phones */
#media only screen and (max-width : 480px) {
}
/* Custom, iPhone Retina */
#media only screen and (max-width : 320px) {
}
You want to use min-width not max-width. Since you're query is applying to any screen up to 1920px wide, it is always being applied when your screen is no larger than 1366px wide. max-width == <=, min-width == >=.
/* apply these selectors when the width is equal to or greater than 1920px */
#media only screen and (min-width:1920px) {
}
If suppose my device width is 800px, which media query will apply (execute)?
#media only screen and (min-width : 320px){
}
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px){
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px){
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px){
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px){
}
If i write the css for the device having screen size is between 768px to 991px and i declare it's css in the media query
#media only screen and (min-width : 768px){
}
then first two media queries will also gets applied how to avoid this.
You can use this three media query for 800px of width
based on your option
#media only screen and (min-width : 320px){
}
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px){
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px){
}
#screen-xs-max: 767px;
#screen-sm-min: 768px;
#screen-sm-max: 991px;
#screen-md-min: 992px;
#screen-lg-min: 1200px;
#screen-md-max: 1199px;
//xs only
#media(max-width: #screen-xs-max) {}
//small and up
#media(min-width: #screen-sm-min) {}