Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS How to Make a Website CSS: Cascading Style Sheets Use ID Selectors

div element doesn't connect to my html file

abc {

background-color: red; }

that is the css commands i wrote.

<div id="abc"> <section> <ul> <a href="img/numbers-01.jpg"><li><img src="img/numbers-01.jpg" alt="description 1"></li></a> <a href="img/numbers-02.jpg"><li><img src="img/numbers-02.jpg" alt="description 2"></li></a> <a href="img/numbers-06.jpg"><li><img src="img/numbers-06.jpg" alt="description 3"></li></a> </ul> </section>

that is the html part of code i encapsulated with the div element.

i'm able to change the style of my webpage with the css file, but i'm just cant do it by using the div. thanks for the help!

4 Answers

Hi,

If you have something similar to the following code:

<div class="abc">
This is my content
</div>

You will need to add the following as a style, either within the HTML document or as an external style sheet:

.abc {

}

Please note if you have used <div id="abc"> the above style will need to be:

#abc {

}

Within this you would add your relevant styles. So if you wanted to make the background of that particular div red it would look something like this:

.abc {
background-color: red;
}

If you are using internal styles you should add the styles in in between the <style> and </style> tags at the top of your HTML page:

If you are using an external style sheet you then link the two (HTML and external CSS) using the following in between the <head> and </head> tags at the top of your HTML page:

<link href="css/styles.css" rel="stylesheet" type="text/css" >

Hope I've understood what you required correctly

-Rich

Are you trying to apply some styles with html or what? Not sure I understand what are you up to.

<div style="background-color: red;"> 

This is the way to style elements directly in HTML

You cant type abc alone :

if your div has a class abc, than in css you call it with .abc {} * if the div has an id abc, that you call it with #abc {}

Max Goetz
Max Goetz
5,360 Points

Hi Nimrod,

You will want to define whether abc is an 'id' or 'class' in your css file.

#abc if it's a 'id' .abc if it's a 'class'

Then in the html file you can apply the css rule to your code:

<div id="abc">This should connect to #abc in the css file</div>

<div class="abc">This should connect to .abc in the css file</div>

Hope that helps! :)

Max

thank you guys, that was helpful!

No problem. Hope you managed to sort it :)

-Rich