Hello there,

I'm trying to add css in hook_init() for my module.

drupal_add_css(drupal_get_path('module', 'dropcap') .'/dropcap.css');

It doesn't get added.

Turns out, at the theme level, I have another CSS file called dropcap.css. When I give my stylesheet a unique name the stylesheet is added.

drupal_add_css(drupal_get_path('module', 'dropcap') .'/dropcapstyle.css');

Comments

brahmjeet789’s picture

Hello there,
If you created css file with the same name is not refected on site, because it create confusion for theme system which file will be implemented? so it is better to use file with different name or added your css into same css file. May be this will help you.

Thanks,

dcam’s picture

Category: Bug report » Support request
Status: Active » Fixed

See the drupal_get_css() API documentation:

Themes may replace module-defined CSS files by adding a stylesheet with the same filename. For example, themes/bartik/system-menus.css would replace modules/system/system-menus.css. This allows themes to override complete CSS files, rather than specific selectors, when necessary.

So this behavior is intentional. If you want to avoid collisions then you must rename your stylesheets.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

koosvdkolk’s picture

When using third-party libs, its not always possible to (easily) rename those CSS (and JS) files.

Please check the 'basename' property in drupal_add_css.

phuocdv’s picture

Version: 7.28 » 10.0.x-dev

Thanks