Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML

Can't call an image inside a div

Hey all,

I've had this problem in attempts in a row in two different projects.

I am placing an image inside it's own div. When I call the div it has no effect on the image. The only time I can make the image do what I want it to do is when I give the img a class and call that in my css. Here is a quick example:

In this jsbin: http://jsbin.com/ucuwiy/1/edit

My image has a "logoimg" class and is in a div with the class "logo-img". If you look at the css in my jsbin, I am using the class selector .logoimg to center my image. If you edit that class and call it by the div class my image is in by adding a "-" between logo-img, I would think it would still impact the image the same way. Unfortunately whenever I put images inside a div class and give the div class rules to align the image it never impacts the image the way I anticipate it to.

Can you not edit an image position that is inside a div class?

2 Answers

Elliott Frazier
PLUS
Elliott Frazier
Courses Plus Student 9,647 Points

To select a image inside a div you need to first select the class of the div you want selected, like this .logo-img then add img to select the img element inside the .logo-img div, like this .logo-img img.

@Elliot Thanks! I understand now. What is the best practice semantically? Should I make a separate div class for a single image? OR add a class to the image without div tags?

Elliott Frazier
Elliott Frazier
Courses Plus Student 9,647 Points

it's more semantic/clean just to give the img tag a class and not wrap it in a div. I made a quick codepen that might help.

Elliott Frazier
Elliott Frazier
Courses Plus Student 9,647 Points

it's more semantic/clean just to give the img tag a class and not wrap it in a div. I made a quick codepen that might help.