Media query not working for desktop - html

I'm trying to do a CSS for just my desktop, therefore i used the media query like below to link my css with my desktop.
My desktop resolution is 1440 x 900. Hence, my media query css for desktop is like this below
#media (max-width: 1440px) {
#loginpage {
position:relative;
margin-top:15%;
}
#headerbodyadmin {
position:relative;
margin-top:20%;
}
}
I tried used this method as well.
#media only screen and (max-width : 1440px){
}
Unfortunately, it's not working. I checked the various media query tutorial and this seems to be the correct way to implement css for my desktop resolution 1440x900.
May i know did i do anything wrong here?

Try adding one pixel to your max-width , #media (max-width: 1441px)

I checked the code and it working fine, make sure that you referenced id's in html page also.
Check this URL : http://jsfiddle.net/Ravichand/8kznk/
#media (max-width: 1440px) {
#loginpage {
position:relative;
margin-top:15%;
color:red;
}
#headerbodyadmin {
position:relative;
margin-top:20%;
color:skyblue;
}
}

I checked that and it works, here you can find example
http://jsfiddle.net/7VVsA/
#media (max-width: 1440px) {
#loginpage {
position:relative;
margin-top:15%;
background:red;
}
#headerbodyadmin {
position:relative;
margin-top:20%;
background:yellow;
}
}

Solution 01: Instead of max width. you can use min-width
Like
/*Sizes above 1024*/
#media (min-width: 1024px) {
}
Solution 02: Or you can try adding +1 to your width
Like
/*width 1441 to avoid any other conflict */
#media (max-width: 1441px) {
}

The width and height attribute describes the length for the view port and not the device screen resolution as device-width and device-height. If you use the width attribute it is possible that the considered value is smaller then your screen resolution width, because there is a border around the window or a scroll bar. Browsers on mobile devices usually utilize the entire width of the screen, so you don't see this effect there. Here what MDN says to the width attribute:
The width media feature describes the width of the rendering surface of the output device (such as the width of the document window, or the width of the page box on a printer).
So if you want to trigger the styles if your device has a width resolution of 1440px I would use it like this:
#media (max-device-width: 1440px) {
/* your style */
}
You can read more about this in the MDN documentation. Maybe this question is also interesting.

Related

Maximum size of canvas element

I tried to search but I didn't found suitable answer.
I want to create Canvas that users can draw on it.
But from what I read before there is no option to set canvas size in percent.
So I need to give it fixed value in px, so my question is:
Which width size will suite to all resulution without scrolling horzintally ?
Depends on the users who are going to use the canvas and what it is going to be used for. I would recommend the following:
#media (min-width: 300px) {
.myCanvas{
width:300px;
height:533px;
}
}
/*Large phone Size*/
#media (min-width: 600px) {
.myCanvas{
width:600px;
height: 1066px;
}
}
/*Tablet and Standard Size*/
#media (min-width: 1920px) {
.myCanvas{
width:1920px;
height:1080px;
}
}
Unfortunately, the above code won't work (which is a bummer) as the width and height need to be defined in the HTML tag, however you can still use these sizes for scaling purposes depending on who you're designing the canvas for.

Media Queries help? - Desktops

I'm trying to target a desktop with the screen size 1944 by 1080. I do this the normal way..
#media screen and (max-width: 1944px) and (max-height: 1080px) {
.about-section {
margin-top: 600px;
}
.container h3 {
position: relative;
top: -200px;
}
}
When I do this though, it affects my default resolution - 1440 by 900 -.
I'm confused does this mean I will have to rewrite code underneath this query for my default resolution?
So I want the header to be in a different position when viewed on a larger screen?
But I want the default header to not be affected by this?
I feel like I'm missing something, I know it cascades but surely the desktop query doesn't need to be at the top of the CSS file.
Any help would be greatly appreciated!
max-width means it will affect any browser with a screen lower than that value. If you want to target those dimensions and above only then use min-width instead.
You can use
#media screen and (max-width: 1944px) and (max-height: 1080px) and (min-width: 1441px) { }
To target your code to only > 1440px wide.
however you should probably just use
#media screen and (min-width: 1441px) { }

Apply CSS rule only on computer screens, not on mobile and tablet

I have a logo in my header that's too small. I found this piece of code where I can increase the size but I only want it to apply to computer screens and not to mobile or tablet. The code is:
.site-title img {max-width:100%; height:auto}
.site-description {display:none}
I want to change the 100% to 200% but only on computer screens.
Can somebody tell me which code makes that happen?
Responsive Web Design, using media-queries:
#media screen and (min-width: 800px) {
// this css will only be used when the screen size is min 800px
}
Media Queries are used to apply CSS rules to only matching devices. Specify a max-width or min-width to apply the style rules to.
#media screen and (min-width: 720px) {
body {
background-color: skyblue;
}
}

CSS: max-width for #media query not working

(It works on other browsers but not chrome)
I want to apply a style only when the browser size is less than 1400px
with max-width not working
#media only screen and (max-width:1400px) {
.heading-left {
left: -0.5%;
}
}
with min-width its working
#media only screen and (min-width:480px) {
.heading-left {
left: -0.5%;
}
}
But also alters when browser width is above 1400px (I know thats how it works but max-width is not working)
Fiddle for this
https://jsfiddle.net/j4Laddtk/
Have you tried adding the viewport in?
<meta name="viewport" content="width=device-width, initial-scale=1">
Working JSFiddle
Viewport is used when rendering responsive pages and is therefore mostly used when dealing with mobile websites, but when dealing with media queries it helps tell the CSS what the actual device-width is.
Is your browser zoom-ed at different than 100% level ? If so, zoom to 100% (Ctrl+MouseWheel)
Try this method.
This will target based on device
#media screen
and (max-device-width: 1400px)
and (min-device-width: 480px)
{
.heading-left {
left: -0.5%;
}
}
To target based on browser window area
#media screen
and (max-width: 1400px)
and (min-width: 480px)
{
.heading-left {
left: -0.5%;
}
}
You need to place the #media queries after you declare your standard
Another thing that can happen is that you do something really stupid like:
#media only screen and (max-width: 1400) { ... }
Make sure you put the px to identify what the quantity of your max-width is.
#media only screen and (max-width: 1400px) { ... }
Not that I've ever been stuck for an hour on something so simple..
This worked for me
#media screen and (max-width: 700px) and (min-width: 400px) {
.heading-left { left: -0.5%; }
}
If you've tried everything and you're still stuck, remember that media queries need to be at the bottom because CSS is applied from top-down.
If you have
.container {
color: white;
}
and you want the font to be pink for screens less than 600px wide, your other media query needs to be below the original .container style.
.container {
color: white;
}
#media only screen and (max-width: 600px) {
.container {
color: pink;
}
}
So if your media queries are at the top the default colour of white will override the media query for pink.
This problem caused me several hours to figure it out with Bootstrap 3 when it just doesn't work. The reason is in the header of each web page, it needs this meta view element.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
More details https://www.w3schools.com/css/css_rwd_viewport.asp
#media only screen and (max-width: 1000px) {
/*Don't forget to add meta viewport in your html*/
}
If it's not working try to inspect elements in the browser by navigating to the network in developer tools and toggling disable cache.
Sometimes it's not working because of the browser cache.
There is one thing I would like to add here, which is only applicable if you have different CSS files. If some values do not seem to be having any effect then check if the CSS file that has the media queries is at the bottom inside the element or not. It is best to always put the media queries CSS file (if made in a different file) at the bottom of all other CSS links.

#media dependant from zoom factor?

I am trying to understand the #media in CSS, and it seems that max-width has not relation with screen resolution, but the window size itself, here is the code:
#media (max-width: 2000px) {
div
{
width:100px;
height:100px;
background:red;
}
}
#media (max-width: 1000px) {
div
{
width:100px;
height:100px;
background:blue;
}
}
at zoom 100%:
but, at zoom 150%
I tried it on Chrome and Firefox, and the same thing happened.
So what is the right code to control the CSS independent of the zoom factor?
Don't look only at max-width, #media works in different way.
I learned how use it by following this great tutorial with examples:
[http://css-tricks.com/css-media-queries/]