Responsive css same width different height - css

Lets say i want to make my div responsive for same width but different height.
Same width but if height is different, it will optimize the div different, like the code below but it is not working.
#media all and(min-width:1280px) and (height:768px){
#myDiv{height:84%}
}
#media all and(min-width:1280px) and (height:1200px){
#myDiv{height:97%}
}

Try this code
#media screen and (min-width: 1280px) and (max-height: 768px){
#myDiv{height:84%}
}
#media all and(min-width:1280px) and (max-height:1200px) and (min-height: 769px){
#myDiv{height:97%}
}

Related

Simple question about media screen. How to use both width and height (each one depends on other)?

So what I have is one with max-width: 992px, another is max-height: 732px and max-width: 992px. What I want is to media screen do something only if both height and width are lower than max.
I have this:
#media screen and (max-height: 753px) and (max-width: 992px){
}
How it should be?
Nvm, just place #media screen inside another.
You can use nested media queries. Something like this
#media (max-width:992px) {
#media (max-height:432px) {
.test-div{
background-color: blue;
}
}
}
Maybe this works well in your case
#media screen and (max-height: 753px) , screen and (max-width: 992px) {
....
....
}
Check Documentation Here
You should use only end in between your height and width property
#media (max-width: 992px) and (max-height: 732px) {
/* CSS stuff */
}

Issue with media queries and heights

I have two media queries like so:
#media(max-height: 1100px) and (min-width: 1200px) {
}
and this
#media(min-height: 750px) and (min-width: 1200px) {
}
My browser screen height is 779, What I am trying to do is apply css code if my screen height is 750px or less and width is 1200px or more. Also apply css code if my screen height is more than 750px and width is 1200px or more.
What am I doing wrong? Currently my #media(max-height: 1100px) and (min-width: 1200px) is overriding the #media(max-height: 1100px) and (min-width: 1200px) code.
Try the following, I believe you are missing a keyword or two... Also, if your desire is to have specific styling be applied on screens smaller than 750, you need to indicate a max-height of 750, not a min-height. (I did not change these below to reflect the max/min, only added in screen and).
#media screen and (max-height: 1100px) and (min-width: 1200px) {
}
#media screen and (min-height: 750px) and (min-width: 1200px) {
}

Apply css styles specific to screen resolution

How do i apply styles for differnt screen resolutions
For example: I have a computer with max screen resolution of 1366 X 768
and want to specify css styles only for this resolution .
Css #media rules only take into consideration min-width and max-width of the browser how do i target for specific resolution.
Use the resolution tag i.e. :
#media (resolution: 150dpi) {
p {
color: red;
}
}
More explantations and syntax here: https://developer.mozilla.org/en-US/docs/Web/CSS/#media/resolution
Try this:
#media screen and (min-width: 1366px) and (max-width: 1366px)
and (min-height: 768px) and (max-height: 768px) {
/* style */
}
Use width and height mediaqueries
#media (width: 1366px) and (height: 768px) {
:root { background: yellowgreen; }
}
to match a viewport of 1366x768 px
Codepen example
Anyway it's worth noting that, unless you are in fullscreen mode, that rule won't be applied because the UI of your browser takes some room, so the actual viewport can't be exactly the same of the chosen resolution.
You can try this
#media screen and (min-width: 1500px) and (max-width: 1600px){
/*Your style */
}

Resolution with media screen

I´m using the following in css:
#media screen and (max-width: 400px){
.details-container {width: 121%;}
}
#media screen and (max-width: 640px){
.details-container {width: 201%;}
}
If i try a resolution under 400px, it takes the 640px css as reference, why?
A screen of 400px fits inside both your queries, that means it will get both values but the last one set will prevail per CSS cascading rules.
You can flip the order of the queries or specify a min-width in the second one
#media screen and (max-width: 400px){
.details-container {width: 121%;}
}
#media screen and (min-width: 401px) and (max-width: 640px){
.details-container {width: 201%;}
}

CSS: apply rule only in specific mediaquery?

following situation … 
/* #media screen and (min-width: 480px) */
#media screen and (min-width: 30em) {
#el { background:red; }
}
/* #media screen and (min-width: 640px) */
#media screen and (min-width: 40em) {
#el { background:none; }
}
So if the viewport is smaller than 480px #el should be red, if the viewport is wider it should have no background-color applied!
Is there some css trick to apply this rule only for min-width: 30em so I don't have to "reset" it in the next mediaquery?
Ideas and thoughts on that?
Thank you in advance!
Try in this way
#media screen and (min-width: 30em) and (max-width: 40em) {
#el { background:red; }
}
example fiddle : http://jsfiddle.net/2ySNu/
If you want the background for #e1 to be red below a certain breakpoint, you should use max-width. If you want to apply styling rules for viewports that a greater than a certain breakpoint - that's when you should use min-width. In your example: #media screen and (min-width: 30em), the background will be red only when the viewport is larger than 30em - once it hits 40em it'll revert back to none (based on your other rule). In order to set the background for viewports smaller than 480px simply use max-width, you don't even have to worry about "resetting" because once the viewport exceeds 480px that rule will not apply.
/* #media screen and (max-width: 480px) */
#media screen and (max-width: 30em) {
#el { background:red; }
}
Just remember, the rules you declare in min-width will apply to viewports that have a width greater than that breakpoint width you specify. Whereas rules declared in max-width will apply to viewports that are less/smaller than the breakpoint width.

Resources