Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I’ve got a question about adding CSS to a custom module.

Originally I’ve been given this line:

link rel="stylesheet" type="text/css" media="screen and (max-width: 640px)"    href="mobile.css"

And I’ve converted it into:

drupal_add_css(drupal_get_path('module', 'savingsscore') . '/css/mobile.css', 'screen and          (max-width: 640px');

The file is being attached, but the media setting is wrong and I don’t know what it should be. I’m in Drupal 6.

Thanks!

share|improve this question
before delving into this further, can you let us know what media setting/actual css link it is generating in error? reason I ask is you have either something really obviously wrong or just a cut and paste glitch in your question above. – Jimajamma Feb 14 at 2:48
It wasn't generating an error per se. But instead the css was still effecting screens beyond 640px in width – Stephanie Feb 14 at 14:44
add comment (requires an account with 50 reputation)

2 Answers

up vote 1 down vote accepted

drupal_add_css() is defined as:

drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE)

and in your example, you are doing:

drupal_add_css(drupal_get_path('module', 'savingsscore') . '/css/mobile.css', 'screen and          (max-width: 640px');

which appears to have two problems:

  1. You are skipping the $type argument,
  2. You aren't closing the max-width parenthetical.

I'd suggest trying:

drupal_add_css(drupal_get_path('module', 'savingsscore') . '/css/mobile.css', 'module', 'screen and (max-width: 640px)');

and seeing it that fixes things up.

share|improve this answer
Thank you this did the trick! – Stephanie Feb 14 at 15:49
add comment (requires an account with 50 reputation)

Why not put the media query inside your style sheet?

Wrap everything in:

@media only screen and (max-device-width: 640px) {
  /* Contents of mobile.css goes here. */
}
share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.