3

I spotted this (to me) curious css style in the default Site.css file of an ASP.NET MVC project:

.text-box.multi-line
{
    height: 6.5em;
}

Is .text-box.multi-line just the name of a class that happens to have a dot in the middle of it, or is this a nesting of two classes? Or is it something else entirely? Can you explain?

And can you provide a usage example?

Edit

Thanks for all the answers. This seems to be an omission from the w3schools css reference page.

5
  • 3
    Regarding the omission.. it's not surprising, see: w3fools.com Commented Jun 10, 2011 at 20:29
  • thank you @thirtydot, wasnt aware there was so much against w3schools, i was personally, but nice to know there are a lot of others Commented Jun 10, 2011 at 20:45
  • @thirydot, thanks for that link. Interestingly, HTML Dog (one of the recommended sites) doesn't have what I was looking for either :( Commented Jun 10, 2011 at 20:45
  • 1
    @DanM: Try SitePoint: reference.sitepoint.com/css/classselector that page discusses div.foo.bar. Commented Jun 10, 2011 at 20:50
  • 1
    @DanM sitepoint reference does :) @thirtydot great minds think alike. Commented Jun 10, 2011 at 20:51

5 Answers 5

5

it matches an item with both classes, ie.

<textarea class="text-box multi-line"></textarea>

It will not match if the item only has 1 of the classes. It will match if the item has those two classes plus additional ones.

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

Comments

3

It means that the element has both classes.

It will select an element with the class text-box that also has the class multi-line

This would be the same:

.multi-line.text-box {}
.text-box[class~="multi-line"] {}

An example:

<p class="multi-line text-box some-other-class"></p>

Comments

3

It's selecting an element like this:

<* class="text-box multi-line"></*>

Any element that has both the text-box and multi-line classes.

Comments

2

It will select this element:

<textarea class="text-box multi-line" />

Or any element with both the text-box and multi-line classes for that matter.

Comments

2

Here's a quick little fiddle to show the difference:

http://jsfiddle.net/sGn2v/

basically it'll match an element having BOTH classes!

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.