2

I have HTML like this:

<div class = "address full">

I want to add css. How do I write a selector for a class with a space in it? This is not doing waht I want.

."address info" {
  background: #eee;
}
George
  • 36,413
  • 9
  • 66
  • 103
bernie2436
  • 22,841
  • 49
  • 151
  • 244

5 Answers5

8

You can't - there is no way of having a space within a single classname. So the element you've provided there doesn't have a 'class name with a space in it'. The element has two different classes address and full. You can of course target this element by specifying both classes like this:

.address.full{}

If you really want 'spaces' in your class name, you'll need another way of clarifying what you see as a space, such as hyphenation:

<div class = "address-full">

Or maybe camel-case

<div class = "addressFull">
George
  • 36,413
  • 9
  • 66
  • 103
3

You can't have CSS classes with spaces in them.

What you have are two seperate classes, address and full.

You can specify both of these in a selector as follows:

.address.full
{
   background: #eee;
}
Curtis
  • 101,612
  • 66
  • 270
  • 352
3

The two words will be treated as separate classes. If they will always be used together, consider separating with a hyphen or underscore instead. However, you can target the classes using:

.address.info {
    background: #eee;
}

This is essentially identifying an element with both the class address and the class info. That is technically different from targeting a class of address info.

For example, if you then had a following rule applied to just address it would also be applied to this element.

Brendan Bullen
  • 11,607
  • 1
  • 31
  • 40
2

This is actually 2 classes: address and full

To apply a style to an element having both classes do this:

.address.info {
      background: #eee;
}

...be sure there is no space between the dot-separated class-names in your selector.

Faust
  • 15,130
  • 9
  • 54
  • 111
0

A class cannot have space. It must begin with an underscore, a dash or letter. Also, a class name must be two characters long.

Use hyphen or underscore instead.

Read this for more information.

codingrose
  • 15,563
  • 11
  • 39
  • 58