Nour_Dev
Nour_Dev

Reputation: 55

CSS Classes (Help!)

I'm new to CSS and want to learn how to make webpages. While learning on Codecademy there was a lesson for classes and Ids which got me confused. How should the classes be setup and does it make a difference if it's like this

.content h1 {

}

or

h1 .content {

}

Upvotes: 0

Views: 61

Answers (2)

user10252353
user10252353

Reputation: 66

Firstly, the spaces in between the CSS selectors .content and h1 matter, meaning, if you are trying to make a CSS rule specifically for h1 elements with a class of content, then the rule needs to be formatted as h1.content.

Secondly, a CSS rule with a space in between selectors (e.g. div .bold) is a combinator known as a descendant selector, and in the example div .bold { font-weight: bold; }, it would mean that any elements with class bold descending from any div element would have a bold font weight style applied.

Upvotes: 2

Llazar
Llazar

Reputation: 3322

element.classname mean you are targeting the tag having a class as classname.

element .classname or .classname element mean you are targeting the html element having class classname which is a child/descendent of tag.

Upvotes: 1

Related Questions