This question already has answers here:
#import styles not working in a media query
(8 answers)
Closed 3 months ago.
#charset "UTF-8";
/* import the basis style page */
#import url("body.css");
/* why is this not working? */
/* import alternative style 500px */
#media (min-width: 500px){
#import url("screen_layout_small.css");
}
The screen_layout_small.css file contains :
#charset "UTF-8";
body {
background-color: red;
}
The url "screen_layout_small.css" works when it is not in a #media (works when it is not in a responsive command ?)
I tryed to load it when width >= 500px but it doesn't work.
By the way it does not mather if I use min-with or max-with, the file does not load in the #media.
I think you are using a wrong syntax. It should be:
#import url|string list-of-mediaqueries;
So in your case it should be:
#import "screen_layout_small.css" screen and (min-width: 500px);
I think the mistake is in the syntax. Try the code that I mentioned below
#charset "UTF-8";
/* inport the basis style page */
#import url("body.css");
/* why is this not working???? */
/* import alternative style 500px*/
#media screen and (min-width: 500px){
#import url("screen_layout_small.css");
}
#charset "UTF-8";
/* inport the basis style page */
#import url("body.css");
/* import alternative style 500px*/
#import "screen_layout_small.css" screen and (max-width: 500px);
this is the working code thanks to maria romano
Related
Is there any way to inject (not import) css files into another css file?
I am using less and trying this:
#media screen {
#import (less) url("../Content/components/bootstrap/dist/css/bootstrap.min.css") screen;
#import "fanoe.css" screen;
#import "../Content/components/font-awesome/css/font-awesome.min.css" screen;
#import "../Content/components/jquery-ui/themes/smoothness/jquery-ui.min.css" screen;
#import "style.base.less" screen;
}
However the above does not work - the third party styles does not render and my styles are broken because of missing classes.
(The files locations are correct)
The idea is to have all styles markes as media=screen so I want to have all classes within #media screen {}.
So I want to have something like this in the style.css file:
#media screen {
.bootstrap-class { }
.font-awesome-class { }
.custom-class { }
}
etc.
Or any othe idea how to mark third-party styles as #media screen {} is welcome.
I have a media query and corresponding CSS that sets up a toolset on the right side of the screen in the case for desktop users and on the bottom for mobile. However, it overrides the CSS properties and assigns 0 to both "left" and "right". What I am doing wrong? Please see the screenshot from firebug below.
Here are my media tags:
/*
- Binds all layouts together with imports and mediaqueries.
*/
//#import "libs/reset.less";
#import "mediaqueries/global.less";
#import "mediaqueries/desktop.less";
#import "mediaqueries/mobile.less";
#media only screen and (min-width: 480px) {
.mqMobile; /* Use mix-in to make sure that the styles are expanded inside the mediaquery */
}
#media only screen and (min-width: 992px) {
.mqDesktop; /* Use mix-in to make sure that the styles are expanded inside the mediaquery */
}
For the mobile media query, use right: auto. This should override the normal CSS, and switch the right property from 0 without actually specifying a specific value. For example:
#media only screen and (min-width: 480px) {
.mqMobile {
left: 0;
right: auto;
}
}
U need to add media query in ur css file.
This will target all
#toolset{
float:left;
}
This will target mobile
#media only screen and (max-device-width: 480px) {
#toolset{
float:right;
}
}
Refer to this:
http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
I'm using WinLESS, a LESS compiler for Windows. In style.less, I'm using #import directives to import my 768up.less and 1030up.less, etc.
The compiled style.css has the contents of 768up.less and 1030up.less parsed inline, for example:
style.less
#import "normalize.less";
/* base styling here */
#media only screen and (min-width: 768px) { #import "768up.less"; }
#media only screen and (min-width: 1030px) { #import "1030up.less"; }
style.css
/* imported normalize */
html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } /* etc */
/* base styling */
.wrap { margin: 0; padding: 0 5px; } /* etc */
/* imported 768up */
.wrap { padding: 0 20px; }
/* imported 1030up */
.wrap { padding: 0 30px; }
Doesn't this defeat the purpose of the #import which are mixed with #media? I mean, the filesize of style.css is now the sum of all imported + compiled files.
Even if the browser won't use 1030up because of small screen size, will it still have downloaded style.css in its entirety?
Isn't the compiled style.css supposed to contain the #import directives unchanged, so that style.css becomes more lightweight and simply instructs to browser to retrieve additional styling if the #media criteria is met?
Is WinLESS compiling these CSS files wrong for me?
Ideally, I'd like to see the following:
/* normalize */
#import "normalize.css";
/* base styling */
.wrap { margin: 0; padding: 0 5px; } /* etc */
/* progressively enhance styling to accomodate larger screens */
#media only screen and (min-width: 768px) { #import "768up.css"; }
#media only screen and (min-width: 1030px) { #import "1030up.css"; }
Please, if I'm misunderstanding the whole concept of #import, enlighten me!
Reducing round trips generally improves performance more than reducing sizes.
It's the same idea as using sprite sheets. Making 4 requests for 1kb is a lot worse than making 1 request for 20kb.
In this case, it can't even do the requests concurrently. It must get the first file, parse it, and only then does it realize it must go back to the server to get another file.
Also mind how gzip works. 1kb+1kb != 2kb.
If you suspect you're in a case where you'd rather keep the files split, LESS only inline includes #import if it's a .less, so try:
#media only screen and (min-width: 768px) { #import "768up.css"; }
#media only screen and (min-width: 1030px) { #import "1030up.css"; }
(note the .css instead of the .less)
More details can be found by doing a control+f, search for "Importing" on http://lesscss.org/
You can enforce the import type it's doing like:
#import (css) "foo.bar";
#import (less) "foo.bar";
I am trying to import a style based off a media query but the import is not being triggered If i put styles directly in the media query they are rendered to the page.
Here is a link to the live site http://update.techbasics.ca
Here is my style.css with the media queries and the imports
I am using wordpress if that helps debug.
#import url('base.css');
/******************************************************************
Site Name: Tech Basics
Author: Anders Kitson
Stylesheet: Main Stylesheet
Here's where the magic happens. Here, you'll see we are calling in
the separate media queries. The base mobile goes outside any query
and is called at the beginning, after that we call the rest
of the styles inside media queries.
******************************************************************/
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; }
/*****************************************************************
BASE CSS
*****************************************************************/
/*****************************************************************
MEDIA QUERIES
*****************************************************************/
#media only screen and (min-width: 480px) {
#import url('min480.css');
}
#media only screen and (min-width: 600px) {
#import url('min600.css');
}
#media only screen and (min-width: 768px) {
body {
background: purple; } }
#media only screen and (min-width: 992px) {
body {
background: orange; } }
#media only screen and (min-width: 1382px) {
body {
background: url("../img/noisy_grid.png"); } }
/* iPhone 4 ----------- */
#media only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5) {
#import url('base.css');
}
and here is min600.css (located in the same directory as the style.css file)
header {
text-align: left; }
body{
background: green;
}
try that kind of code
#import url("/inc/Styles/full.css") (min-width: 940px);
Here is the solution:
/* Everything 700px and lower */
#import url("./700.css") only screen and (max-width: 700px);
Did you use like this?
You can write:
#import url('path.css') (screen and min/max-width: 600px);
You can add path as you use #import
or like:
#import url(style.css) (screen and min-width:600px);
MDN states that #import cannot be nested and must come before all other declarations except #charset.
The syntax is as follows:
#import url;
#import url list-of-media-queries;
https://developer.mozilla.org/en-US/docs/Web/CSS/#import
It works fine, try to resize your window and you will see the colors changing
As I can see in my main window on my screen (1920x1080) the CSS rule
body {
background: url("../img/noisy_grid.png");
}
Located in style.css , line 37-38 fires first, that's why you can't see the orange color.
Try re arrange your css rules
I had the same problem and after searching without finding a good solution, I ended up moving the media queries to the imported css instead. And in fact all the style sheets are downloaded even if they are not applied anyway (see CSS media queries).
Then what's the point of having separate files? For me, it keeps things organized. Using your example:
#import url(min480.css); /* min-width: 480px */
#import url(min600.css); /* min-width: 600px */
Then on the min600.css:
/* min600.css */
#media only screen and (min-width: 600px) {
header {
text-align: left;
}
body {
background: green;
}
}
true statement
#import ('filename.css') mediaType and (feature: value);
example:
#import (responsive.css) screen and (min-width: 320px) and (max-width: 480px);
notice:
if use #import for CSS file, this file should not attachment in <link> tag. otherwise dose not work Styles.
in my case I should first add this meta tag in my html
<meta content="width=device-width, initial-scale=1" name="viewport" />
I have a styles.css file. Now i'm going to write css - media queries for mobiles/tablet devices. In styles.css, i mentioned differnt font-sizes to diffent classes. Now i need to apply all 'font-size's to 'medium' for mobile devices. How to apply?
i have applied font-size:medium; to mediaqueries css. it is working fine. but for ex:.dynamicdata{font-size:14px;} in style.css. i need to apply replace font-size:medium to all classes which i have applied fonts-sizes for mediaqueires css.
I would do this...
#media screen and (max-width: 480px) {
/* disable webkit text size adjust (for iPhone) */
html {
-webkit-text-size-adjust: none;
}
.class1, .class2, .class3 {
font-size: 1.2em;
}
}