A Newbie Question

Maybe it’s too easy to ask but I couldn’t find its solution :upside_down_face:
In my page, I used an image. then a paragraph and then another image.
I created a div (img-div) for my first image then I created another div (id=“tribute-info”) for the paragraph.
Now can’t I use the same div (img-div) for my second image?
I’m asking this because I want to format my image sizes with a single div in my CSS file?
I hope that my question is understandable :slight_smile:

@mjozdi Welcome to the FreeCodeCamp forums! It might be easier to see your code. You can do that by clicking the button that looks like this </> then putting in your code. But I think I know what you might be talking about. If you are using this div for two images they would have to be one right above the other. You can’t really split a div into two pieces. It could work maybe if you gave the div a class, not an id. Happy Coding! :smile:

1 Like

Hello, id attribut can be used for only one element. If you want to use the same CSS settings for several images you can use class attribut instead of id.

2 Likes

Thank you for the fast responses :v:
So I should use class for my purpose. But for the tribute page project I have to use id.
Therefore another simple question, can I use both id and a class in a div? so that I can use class name for css formatting?

@mjozdi That is a good question and yes! You can use both. For that I would give it an ID and a class, you could then stick this class onto your second image.

<img src="whatever" class="whateverDivIs">

I think that should work!

2 Likes