2

Suppose I have the following css rule:

.blah { Rules }

and I use it as such

<div class="blah">

Now suppose, somewhere in my doc I need to add margin-bottom: 10px to one of these divs with class name blah so I can make it as specific as possible,

Should I declare it as

.blah.mar-bot-blah { margin-bottom: 10px; }
or 
.blah .mar-bot-blah { margin-bottom: 10px; }

to use it as <div class="blah mar-bot-blah">

1
  • FYI, using a space in between classes is for descendants. So you would use second example if .mar-bot-blah is a child element of the .blah element. Commented Jul 5, 2012 at 15:04

2 Answers 2

5

Declare it as:

.blah.mar-bot-blah { margin-bottom: 10px; }

It will match elements that have both the classes .mar-bot-blah and .blah.

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to make it really specific, I would use your first solution. (Warning: IE6 Can't handle this!)

In most cases it should suffice to just use .mar-bot-blah { margin-bottom: 10px; } so you can re-use this setting in other classes as well.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.