Hi there,

the following drupal_add_css example doesn't work as expected with Opera (tested with 11.50)
but displays the given inline css code to the user.

This bug does only occur if you set '!IE' => FALSE.

<?php
/**
 * Implements hook_init().
 */
function bugdemo_init() {
  drupal_add_css('body{background:green}', array(
    'type' => 'inline',
    'browsers' => array('IE' => TRUE, '!IE' => FALSE)
  ));
}

Result screenshot is attached.

CommentFileSizeAuthor
Drupal Bug.jpg16.2 KBjantimon

Comments

quicksketch’s picture

Title: Conditional inline css doesn't work in opera » Conditional Inline styles show as plain text to the end-user in Opera
Version: 7.4 » 8.x-dev
Priority: Major » Normal

I've confirmed this problem in both 7.4 and the latest 8.x code. We'll need to fix this in D8 first and include the backport in Drupal 7.

I'm suspecting that this problem is because the conditional stylesheet "fix" we have doesn't play nicely with Opera, which isn't surprising considering the huge mass of comment hacks in here. Here's the code output when combining conditional IE stylesheets with inline CSS:

<!--[if IE]>
<style type="text/css" media="all">
<!--/*--><![CDATA[/*><!--*/
#main{background:green}

/*]]>*/-->

Somewhere in there Opera looses track of what's an HTML comment and what is not, resulting in the content being displayed to the end-user.

Of course a simple work-around is just to not use inline styles with conditional styles. Even when using inline styles, this appears to only affect Opera currently (I confirmed both Opera 11.05 and 11.5 have this problem).

sonnenmann’s picture

+1 same problem here

dom.’s picture

Issue summary: View changes
Status: Active » Closed (cannot reproduce)

Both drupal_add_css and hook_init have been remove. Please update if necessary, otherwise considered as deprecated.
#2168113: Add leading underscore and other discouragement to drupal_add_css() and drupal_add_js()
#1911728: Remove hook_init()