0

OK, simple question I know - but which of these is correct?

I am trying to hide this div:

<div class="notice important-message">

.notice .important-message {
    display: none
}

or - classes joined together like this:

.notice.important-message {
    display: none
}
Henry
  • 5,195
  • 7
  • 21
  • 34

4 Answers4

3

.notice .important-message

would select the element .important-message in this case:

<div class=".notice>
    <div class=".important-message"></div>
</div>

.notice.important-message

selects this:

<div class="notice important-message"></div>

so the second one would be correct. Check this for more references.

Sai Manoj
  • 3,809
  • 1
  • 14
  • 35
BlakkM9
  • 400
  • 4
  • 17
0

Second is correct. You can also do div.class1.class2 {}

yqing237
  • 61
  • 1
0

Try this

<div class="hide">
.hide {
    display: none;
    visibility: hidden;
    opacity: 0;
}

Mohammad Ayoub Khan
  • 2,422
  • 19
  • 24
0

In this case 2 classes are on same node

<div class="notice important-message">

so to access this code you can use (without space)

.notice.important-message {
    display: none
}

If these 2 classes are on parent child node that is

<div class="notice">
    <div class="important-message">
    </div>
</div>

then you can use (with space)

.notice .important-message {
    display: none
}
Nitin Daddikar
  • 335
  • 5
  • 12