Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Color of Fonts in DIV (CSS)

Tags:

html

css

I am trying to change the color and size of H2 font and H2 link fonts based on the div they are in but have not been successful. What am I doing wrong?

 <style> h2 { color:fff; font-size: 20px; } social.h2 { color:pink; font-size: 14px; } social.h2.h2color { color:purple; font-size: 10px; } tv.h2 { color:green; font-size: 14px; } tv.h2.h2color { color:orange; font-size: 10px; }  </style>   <h2>List of Companies </h2>  <div class="social">   <h2>     <A href="http://www.facebook.com">Facebook     </a>  <span class="h2color">Found in 2004     </span>     </h2>   blah blah blah    <h2>     <A href="http://www.twitter.com">Twitter     </a>  <span class="h2color">Found in 2007     </span>     </h2>  blah blah blah    </div>    <div class="tv">   <h2>     <A href="http://www.fox.com">Fox     </a>  <span class="h2color">Found in 2004     </span>     </h2>   blah blah blah    <h2>     <A href="http://www.nbc.com">NBC     </a>  <span class="h2color">Found in 2007     </span>     </h2>  blah blah blah   </div> 

I am trying to make it look like this:

enter image description here

like image 292
Mike Avatar asked Oct 21 '12 16:10

Mike


People also ask

How do you change the font color with CSS?

Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.

How do I change the font of a div class?

To change font size in HTML, use the CSS font-size property. Set it to the value you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a paragraph, heading, button, or span tag.

How do you change text color to black in CSS?

Color keyword: In an HTML file, enter p { color: black;} to change the color for every paragraph, where black refers to your chosen color. Hexadecimal: In an HTML file, enter p { color: #000000;} to change the color, where 000000 refers to your chosen hex value.


1 Answers

Your first CSS selector—social.h2—is looking for the "social" element in the "h2", class, e.g.:

<social class="h2"> 

Class selectors are proceeded with a dot (.). Also, use a space () to indicate that one element is inside of another. To find an <h2> descendant of an element in the social class, try something like:

.social h2 {   color: pink;   font-size: 14px; } 

To get a better understanding of CSS selectors and how they are used to reference your HTML, I suggest going through the interactive HTML and CSS tutorials from CodeAcademy. I hope that this helps point you in the right direction.

like image 76
Blackcoat Avatar answered Sep 21 '22 16:09

Blackcoat