1

I want to give a div 2 classes, however, one of the class names has a space in it. I want to give a div the "section scrollspy" class and carousel class.

Will putting a space in between classes still work?

For example:

<div class="section scrollspy carousel">

Or is there a better way to do this?

Azeem
  • 11,148
  • 4
  • 27
  • 40
peterbonar
  • 559
  • 3
  • 6
  • 24

2 Answers2

3

Spaces are invalid in class names, the normal way to do it is to use a hyphen instead of a space so it would be:

<div class="section-scrollspy carousel">

Theres a good post here that talks about valid CSS names.

Peter Featherstone
  • 7,835
  • 4
  • 32
  • 64
1

If you want to preserve the space character, you'll have to update your css :

.section.scrollspy {
   // css rules
}

but it's still two class here. If you want to use just one class, you'll have to use Peter Featherstone's answer :

<div class="section-scrollspy carousel">

Mattew Eon
  • 1,722
  • 1
  • 21
  • 38