1 Replies - 225 Views - Last Post: 28 April 2020 - 04:21 AM

#1 H0mus 3x   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-April 20

CSS - ID SELECTORS [ERROR]

Posted 28 April 2020 - 04:00 AM

<!DOCTYPE html>
<html>
    <head>
     <title>This is document title.</title>
     <style>
         h1 #blue { color: blue;}
		 #red {color: red; }  
		 #green h2 {color: green;}
     </style>	 
	</head>
    <body >
	<h1 id="blue"> color</h1>
	    <p id= "red" >red</p>
    <h2 id="green">green</h2>
	</body>
</html>


above is my code. ERROR is that [h1] is not being red and also [h2] is not being blue. Some help please..

This post has been edited by andrewsw: 28 April 2020 - 04:22 AM
Reason for edit:: added missing [code][/code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: CSS - ID SELECTORS [ERROR]

#2 andrewsw   User is offline

  • palpable absurdity
  • member icon

Reputation: 6901
  • View blog
  • Posts: 28,559
  • Joined: 12-December 12

Re: CSS - ID SELECTORS [ERROR]

Posted 28 April 2020 - 04:21 AM

Please wrap code in CODE tags.

h1 #blue { color: blue;}

This will colour an element of id blue which is a child of (contained within) an h1 element.

h1#blue would colour an h1 element having this id, but, when you have an id you do not need to qualify it, just #blue. Id's are unique so there is no ambiguity about which element you are formatting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1