-1

What does it mean in css when a class comes right after an id (there is no space between them)? such as this:

#bgimage.header-image

Thanks

PapT
  • 603
  • 4
  • 14
  • 30
  • it means an element with both that id and class - if there is no space between selectors it means that it must have both. You may find this useful: https://www.smashingmagazine.com/2007/07/css-specificity-things-you-should-know/ – Pete Nov 13 '17 at 14:21
  • 1
    It means what the basic syntax rules of the language say it means. This is a poorly researched question IMO. – underscore_d Nov 13 '17 at 14:24

3 Answers3

2

It means that this formula will be used for the same element, such as

<div id="bgimage" class="header-image"></div>

If you'll make space between #bgimage and .header-image then it will be used to:

<div id="bgimage"><div class="header-image"></div></div>
Dawid Winiarczyk
  • 424
  • 3
  • 14
1

It means an element with id and class at the same time. Eg:

<div id="bgimage" class="header-image"></div>
Nick
  • 422
  • 2
  • 9
0

See the below example for difference between the selectors.

/* _class should be a child of _id */
#_id ._class{
  background: #ccc;
  width: 100px;
  height: 100px;
}

/* It should have both id and class */
#_id._class{
  background: #faa;
  width: 100px;
  height: 100px;
}
<div id="_id">
  <div class="_class">
      Box 1
  </div>
</div>


<div class="_class" id="_id">
  Box 2
</div>
bhansa
  • 7,282
  • 3
  • 30
  • 55