Lesson 4 css overview - not clear!


#1

https://www.codecademy.com/en/courses/web-beginner-en-TlhFi/0/4?curriculum_id=50579fb998b470000202dc8b

Hi, it may seem dumb. if I consider the following code (putting CSS in the same file as HTML) shouldn't the style tag "color: purple" apply just to the head section? since it's nested into the tags...
In fact the result page gives the BODY paragraph colored in purple.
It doesn't seem really logic...

<!DOCTYPE html>
<html>
	<head>
		<style>
			p {
				color: purple;
			}
		</style>
		<title>Result</title>
	</head>
	<body>
		<p>Check it out! I'm purple!</p>
	</body>
</html>

Thanks!
Alice


#2

You can't have paragraphs in the head soooo...

How is it supposed to apply there?


#3

That's my point. The code I copied was the one given in the lesson, not written from me...


#4

doesn't matter, you use <style></style>, which means you are using css, which means it is applied to whole document


#5

Thank you so much hehe


#6

Well, you should have written it yourself, because you are more likely to learn it that way, just saying.

As Cade said:

Which is a very good point. You can only style things in the body, no matter where you put the style tags.



Even this CSS code that you posted

p {
  color: purple;
}

tells you what it's styling. See there where it says p { ? That's the opening, and the p represents the <p></p> tags in the body, meaning that the paragraph will have the styling color: purple.