0

i have created a view block and added some fields to it,i want to change the style of those fields with css, is there a way that i can do it. "Thank you"

2

Click on the field you want to add a css class to, select style settings, and customize field html and check create a css class. Give it a name and simply add the class to the css file of your theme

enter image description here

  • i did that but it wont work – user2575884 Jul 17 '13 at 9:47
  • class is not inheriting from another class. – user2575884 Jul 17 '13 at 10:00
  • i am using div and i also tried -Use Default- – user2575884 Jul 17 '13 at 10:06
  • yes i have cleared the cache . – user2575884 Jul 17 '13 at 10:16
  • 1
    Have you inspected the views output to check if the class you have added is added or not? If class is added, then only two possibilities I can think off - The '.css' file has not been included in that page where you are displaying the result, or, the css code has been overridden at some point.If the class itself is not getting added then two possibilities I can think off are - The particular views theme has been overridden in template.php or in views tpl file, or, you have added class in one of the multiple views and accessing another. Hope it helps – dhrubaj Jul 17 '13 at 12:25
0

If it's only one or two block displays of views, consider calling template_preprocess_block() in your template.php file, adding the class(es) you want to the block level, then styling the fields within the block using specificity in your CSS selectors. Example:

<?php
    function MYTHEME_preprocess_block(&$variables) {
        if (your condition here to target the blocks you want) {
            $variables['classes_array'][] = 'yourClass';
        }
    }
?>

While it would be best to have Drupal attach the CSS classes for you, a second option would be to use jQuery's .addClass() method, especially if it's only one or two blocks. Example:

$('#myBlock').addClass('myClass');

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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