How to apply drupal_add_css by block_id in Drupal? I am trying to apply css by block_id or block title.

if($template_name=="BOhhjI" &amp;&amp; $block_name=="block1" ){
  drupal_add_css(drupal_get_path('module', 'MyModule') . '/css/grid.css', array('group' =&gt; CSS_DEFAULT, 'every_page' =&gt; FALSE));
 }
  else if($template_name=="calender" &amp;&amp; $block_name =="block2"){
  drupal_add_css(drupal_get_path('module', 'MyModule') . '/css/carousal.css', array('group' =&gt; CSS_DEFAULT, 'every_page' =&gt; FALSE));
 }
 else{
  drupal_add_css(drupal_get_path('module', 'MyModule') . '/css/MyModule.css', array('group' =&gt; CSS_DEFAULT, 'every_page' =&gt; FALSE));
 }


But, drupal_add_css apply css to whole page. I have a single template and multiple css.I need to switch css on a given condition. Any way to achieve this?

Edited: Following solution from comments

function Module_Name_block_view($delta = '') {
    $blocks = array();
    $query = db_select('Table Name', 'n')
            -&gt;fields('n')
            -&gt;execute();
    $block_data = $query-&gt;fetchAll();
  foreach ($block_data as $block_query) {
  $macname = $block_query-&gt;title;
  if($block_query-&gt;options == 'BOI'&amp;&amp; $delta == $macname){

    $blocks['subject'] = t($block_query-&gt;title);
    $blocks['content'] =&gt; array
      (
        '#markup' =&gt; block_content($block_query-&gt;selected_type_list),
        '#attached' =&gt; array
        (
          'css' =&gt; array('/css/grid.css'),
        ),
      );
}
  }
  return $blocks;

}
You can try this code. Paste this code in file template.php

function YOURTHEME_preprocess_block(&amp;$vars) {
  // use dpm($vars) to see struct of variable $vars
  $delta = $vars['block']-&gt;delta;
  switch ($delta) {
    case 'abc':
      //add css here
      break;
  }
}


Block ID are 


string 'block'
$variables['block']->module
$variables['block']->delta


You can check block delta to use drupal_add_css()