Media queries working only partially - css

Basically I'm playing around with these and I noticed that some of the properties do change as I want. Some (text-transform and font-size) have no effect (they work outside of the media query but not in). The p and #icon part work flawlessly, as well as color and font-family for .title, so I have zero clue as to why this happens.
Relevant code snippets:
#media only screen and (max-width: 1000px) {
p {
background-color: blue;
}
#icon {
display: none;
}
.title {
color: red;
text-transform: lowercase;
font-family: Arial;
font-size: 10px;
}
}
And for the regular screen size I have
.title {
text-transform: uppercase;
font-size: 35px;
font-weight: 300;
}
And in the HTML part
<h1 class="title" style="text-align: right; margin-bottom: 0px;">Jane Doette</h1>

For rules where the selectors are equally specific, the last one takes precedence.
Make the rule inside the media query more specific, for example changing .title to h1.title, or place the rules for regular screen size before the media query.

My guess is that your media query is placed before the non-media query style. If so, put your media query after: JS Fiddle - Media Query Last
.title {
text-transform: uppercase;
font-size: 35px;
font-weight: 300;
}
#media only screen and (max-width: 500px) {
p {
background-color: blue;
}
#icon {
display: none;
}
.title {
color: red;
text-transform: lowercase;
font-family: Arial;
font-size: 10px;
}
}
Otherwise, if the media query is first, the last styles in the style sheet will take precedent: JS Fiddle - Media Query First

Related

iOS Outlook App only allowing a single media query in HTML email

I am wanting to change the font size of some text in an HTML email at 2 different screen widths with media queries. This works as expected on all devices/clients except in Outlook App for iOS.
Here is an example of the inline HTML:
<td class="para" align="left" style="border-collapse: collapse; mso-line-height-rule: exactly; font-family: Times, 'Times New Roman', serif; font-size: 17px; color: #333333; line-height: 24px; text-align: left; text-indent: 29px; padding: 20px 0 0 0;"><span style="font-family: Times, 'Times New Roman', serif !important;">some text here</span></td>
Then I have the following CSS:
<style>
#media only screen and (max-width:600px) {
.para {
font-size: 18px !important;
}
}
#media only screen and (max-width:445px) {
.para {
font-size: 20px !important;
}
}
</style>
If I only have one of the media queries, it works as expected in the Outlook App for iOS, but when I add the second one it no media queries work at all.
Am I doing something wrong or is this just something that you have to work around with iOS Outlook?
The issue is due to a bug in their implementation, as documented here: https://github.com/hteumeuleu/email-bugs/issues/92
The easiest solution, since perhaps your minifying code may be removing whitespace and creating the double curly braces, }}, is to close the style block and start a new one, i.e.:
<style>
#media only screen and (max-width:600px) {
.para {
font-size: 18px !important;
}
}
</style>
<style>
#media only screen and (max-width:445px) {
.para {
font-size: 20px !important;
}
}
</style>

How to handle both width and height without conflict?

I woud like that if my viewport width is smaller than 330px, the paragraphs font will be 9px, whatever its height.
In the same time, I also would like that if my viewport height is smaller than 330px, the paragraphs font will be 9px, whatever its width.
I have tried different orders, with or without !important keywords, I can't achieve the expected result.
There is always either the width or the height rule which conflicts with the other.
Could I handle such situation in CSS?
Here is my code :
p{
font-size: 16px;
}
#media (max-width:600px){
p{
font-size: 14px;
}
}
#media (max-width:440px){
p{
font-size: 12px;
}
}
#media (max-width:330px){
p{
font-size: 9px;
}
}
#media (max-height:600px){
p{
font-size: 14px;
}
}
#media (max-height:440px){
p{
font-size: 12px;
}
}
#media (max-height:330px){
P{
font-size: 9px;
}
}
Just use logic for #media queries. You can read more about them here.
For your problem solution would be code below (as comma creates a OR condition)
#media (max-width: 330px), (max-height: 330px) {
p { font-size: 9px; }
}

"#media all and (max-width: 945px)" not changing font-size at and below 945px

I've looked at several posts on the subject (example, example), and my reasoning should be solid:
#media all and (max-width: 945px) {
div#browser-nav-nav-bar a, div#browser-nav-nav-bar p {
font-size: 0.8rem;
}
}
div#browser-nav-nav-bar a, div#browser-nav-nav-bar p {
color: rgb(255,255,255);
font-size: 1.2rem;
margin: 0 0.5rem;
padding: 0.5rem 1rem;
line-height: normal;
}
However, the font size isn't changing. I can't figure what I'm doing wrong. Here's a JSFiddle:
http://jsfiddle.net/2hLow0c5/
Your selectors are identical (so have equal specificity) so the last font size defined will be the one that is applied.
Move the #media block to the end of the stylesheet.

CSS, Confused about #media with classes

I am trying to take my first forray into using "responsive" css, and I am working with this new #media ....... thing... and I am having a big of trouble understanding some of it. I have read up on it on multiple websites to form my code, and it isn't doing what I expected it to do, so I am getting more frustrated.
I basically have a place in text where, under normal circumstances, I want it to be font-size: 64px;, but if the screen gets very small (480px), I want it to be downsized to like 24px;. I added some other ridiculous properties to make sure I am actually getting the different result, but I am quite confused still.
So this was my approach...
#media (min-width: 480px) {
.name {
color: green;
font-family: "Comic Sans MS";
font-size: 24px;
}
}
.name {
font-size: 64px;
}
<span class="name">This is a really long name</span>
So I expected that when this runs, it will have the normal .name class, and if the resolution dips to 480px or thinner, it will go to the other one. Is this completely wrong? Because this is not what is happening for me.
The .name selector within the media query has the same specificity as the .name selector after the media query. Because of this, the later .name selector will take precedence.
Simply changing the order will fix the issue:
.name {
font-size: 64px;
}
#media (min-width: 480px) {
.name {
color: green;
font-family: "Comic Sans MS";
font-size: 24px;
}
}
If you'd like the styles within the media query to take effect when the screen is 480px or thinner, you should be using the max-width media query:
.name {
font-size: 64px;
}
#media (max-width: 480px) {
.name {
color: green;
font-family: "Comic Sans MS";
font-size: 24px;
}
}

Why isn't my 320px media query being applied?

I have the following two media queries:
#media (min-width: 320px) and (max-width: 359px){
.hero-unit h1 {
margin-bottom: 0;
font-size: 0.2em;
line-height: 0.5em;
letter-spacing: -5px;
color: inherit;
}
.hero-unit p {
font-size: 0.2em;
font-weight: 10;
line-height: 0.5em;
color: inherit;
}
.hero-unit {
background: url("../img/now320.jpg");
height: 5em;
width: 15em;
padding: 0.5em;
margin-bottom: 2em;
background-color: #eeeeee;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
h2 {
font-size: 2em;
font-weight: 20;
line-height: 0.5em;
color: inherit;
}
}
#media (min-width: 360px) and (max-width: 479px) {
.hero-unit h1 {
margin-bottom: 0;
font-size: 0.2em;
line-height: 1em;
letter-spacing: -5px;
color: inherit;
}
.hero-unit p {
font-size: 0.2em;
font-weight: 50;
line-height: 1em;
color: inherit;
}
.hero-unit {
background: url("../img/now360b.jpg");
padding: 1em;
margin-bottom: 2em;
height: 10em;
width: 18em;
background-color: #eeeeee;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
h2 {
font-size: 2em;
font-weight: 20;
line-height: 1em;
color: inherit;
}
}
I'm trying to figure out why the 320 width rule is not being applied at all to my HTML page, even though I've resized it using the responsive design tool in Firefox to have a width of 320px.
I checked the CSS styles using Firebug to see what's going on. I only see the #media (min-width: 360px) and (max-width: 479px) part being applied. That is, its not a case where the CSS rule I think should be applied is being overwritten. What's happening is the rule is never applied at all. Why?
Sometimes browsers just simply don't allow for a viewport to be smaller than a certain size, and I think that line is down around 360, so it may simply not be registering, even with the tool you mention. I can't say, because I'd need to see the live example.
Have you checked the site on an actual mobile device, or at least an emulator? The Opera Mobile Emulator is pretty easy to use.
As an aside, if you want to work mobile first - there is the idea of writing your CSS for 320 devices first, with no media query, as the 'baseline' experience. That is where you specify font families, colors, generally applied styles. Then you add in media queries to work on larger and larger sizes, and that is where you specify changes in layout and text size. The point being - don't wrap your 320-359 styles in a media query as it will be the basic experience for everyone.
If you wish the 320px rule to be applied for all the page you need to write it like this
#media (min-width: 320px)
without any and (min-width....) after it

Resources