2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: bad87fee1348bd9aecf08806
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Use a CSS Class to Style an Element
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								videoUrl: 'https://scrimba.com/c/c2MvDtV'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Description
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'description' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Classes are reusable styles that can be added to HTML elements.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Here's an example CSS class declaration:
							 
						 
					
						
							
								
									
										
										
										
											2019-05-14 01:11:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  .blue-text {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    color: blue;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								You can see that we've created a CSS class called < code > blue-text</ code >  within the < code > & #60 ; style& #62 ; </ code >  tag.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You can apply a class to an HTML element like this:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< code > & #60 ; h2 class="blue-text"& #62 ; CatPhotoApp& #60 ; /h2& #62 ; </ code >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Note that in your CSS < code > style< / code >  element, class names start with a period. In your HTML elements' class attribute, the class name does not include the period.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Instructions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'instructions' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Inside your < code > style< / code >  element, change the < code > h2< / code >  selector to < code > .red-text< / code >  and update the color's value from < code > blue< / code >  to < code > red< / code > .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Give your < code > h2< / code >  element the < code > class< / code >  attribute with a value of < code > 'red-text'< / code > .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Tests
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'tests' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```yml
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								tests:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -  text: Your < code > h2</ code >  element should be red.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert($("h2").css("color") === "rgb(255, 0, 0)", 'Your < code > h2< / code >  element should be red.');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: Your < code > h2</ code >  element should have the class < code > red-text</ code > .
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert($("h2").hasClass("red-text"), 'Your < code > h2< / code >  element should have the class < code > red-text< / code > .');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: Your stylesheet should declare a < code > red-text</ code >  class and have its color set to red.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;\s*\}/g), 'Your stylesheet should declare a < code > red-text</ code >  class and have its color set to red.');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -  text: Do not use inline style declarations like < code > style="color& #58 ;  red"</ code >  in your < code > h2</ code >  element.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    testString: assert($("h2").attr("style") === undefined, 'Do not use inline style declarations like < code > style="color& #58 ;  red"</ code >  in your < code > h2</ code >  element.');
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Challenge Seed
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'challengeSeed' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = 'html-seed' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  h2 {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    color: blue;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h2 > CatPhotoApp< / h2 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< main >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < p > Click here to view more < a  href = "#" > cat photos< / a > .< / p > 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  < a  href = "#" > < img  src = "https://bit.ly/fcc-relaxing-cat"  alt = "A cute orange cat lying on its back." > < / a > 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  < div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < p > Things cats love:< / p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < ul > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > cat nip< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > laser pointers< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > lasagna< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / ul > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < p > Top 3 things cats hate:< / p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < ol > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > flea treatment< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > thunder< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > other cats< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / ol > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / div > 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  < form  action = "/submit-cat-photo" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "radio"  name = "indoor-outdoor"  checked >  Indoor< / label > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "radio"  name = "indoor-outdoor" >  Outdoor< / label > < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "checkbox"  name = "personality"  checked >  Loving< / label > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "checkbox"  name = "personality" >  Lazy< / label > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "checkbox"  name = "personality" >  Energetic< / label > < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < input  type = "text"  placeholder = "cat photo URL"  required > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < button  type = "submit" > Submit< / button > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / form > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / main >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Solution
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'solution' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 01:57:43 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  .red-text {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    color: red;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h2  class = "red-text" > CatPhotoApp< / h2 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< main >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < p > Click here to view more < a  href = "#" > cat photos< / a > .< / p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < a  href = "#" > < img  src = "https://bit.ly/fcc-relaxing-cat"  alt = "A cute orange cat lying on its back." > < / a > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < p > Things cats love:< / p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < ul > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > cat nip< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > laser pointers< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > lasagna< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / ul > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < p > Top 3 things cats hate:< / p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < ol > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > flea treatment< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > thunder< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < li > other cats< / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / ol > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < form  action = "/submit-cat-photo" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "radio"  name = "indoor-outdoor"  checked >  Indoor< / label > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "radio"  name = "indoor-outdoor" >  Outdoor< / label > < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "checkbox"  name = "personality"  checked >  Loving< / label > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "checkbox"  name = "personality" >  Lazy< / label > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label > < input  type = "checkbox"  name = "personality" >  Energetic< / label > < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < input  type = "text"  placeholder = "cat photo URL"  required > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < button  type = "submit" > Submit< / button > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / form > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / main >  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >