2

Is it a bad practice to have styles such as these in the css files ?

#block-block-1, #block-block-7, #block-block-8

I mean, if one was to delete the block and recreate it the styles would no longer be valid.

Or is it best to modify the template and target the selectors in the template ?

0

2 Answers 2

5

It is better not to use the id.

You could use this module Block Class which allows you to add a class to the block and you can then style your css using that class.

4
  • As i have seen it, the number in the ids is sequential; meaning the 1st block created will have id block-block-1(block-block-0, can't seem to remember), the 2nd block-block-2 and so on.
    – SGhosh
    Jan 29, 2013 at 7:21
  • No need for module if he target block name in the class.
    – NenadP
    Jan 29, 2013 at 7:49
  • This is another example. <div class="block block-block contextual-links-region" id="block-block-8"> How would I go about targeting a block name in the class?
    – kine456
    Jan 29, 2013 at 22:26
  • I don't think the block name is available in the class list by default. And if you create a block from the block ui, the block id will be block-block-N, but if you create the block programmatically, the block id will be have the block name. This module - Block Class - provides a text-field in block settings where you can add all your classes and they will be displayed in the class list in your html.
    – SGhosh
    Jan 30, 2013 at 4:17
0

Block names should be also propagated at same level as those id- s, so using them would be more reliable. Try inspecting with Firebug to be sure.

So after recreating a block, editor should take care that names are the same.

1
  • Thank you. This is what I'm seeing <div class="block block-block contextual-links-region" id="block-block-7"> No mention of the block title ...
    – kine456
    Jan 29, 2013 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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