During the lessons I was told that you should only have ONE id per page. I’ve also watched multiple videos that state you should only contain one id per page. I’ve been told that you should always use the class selector (sorry if my terminology is wrong, I’m still learning) over the id because you can only have one per page.
Now I’m going over the “build a tribute page” project and it’s having me put id’s in multiple tags? I’m so confused on this. Could someone please clarify why they are having me do this?
Here is an example with the first three sets of directions.
Your tribute page should have an element with a corresponding id="main", which contains all other elements
You should see an element with an id of title, which contains a string (i.e. text), that describes the subject of the tribute page (e.g. “Dr. Norman Borlaug”)
You should see either a figure or a div element with an id of img-div
I don’t understand why it’s having me do this when I was told you should only have one id per page, I really need some clarification, why id and not class???
Like I’m doing this and I’m getting the checkmarks saying the code passes but I don’t understand it. I don’t want to move on without understanding what I’m actually doing here.
Now I can go into my css and target the img class selector to apply the same styles for all of those images.
.card-img {
/*styles goe here*/
}
Using ids for these projects makes it easier to write tests and check if the user has met the condition for each test case.
Since id names have to be unique, the test is look for that unique id name applied to that element.
So these id’s used during the test are simply to make it easier to see if you did something correctly? If I were actually building a tribute page and not being tested would it be normal to use all of these id’s? Or is this strictly for testing purposes so the “machine” can find my answer. I think I understand what you’re saying but I’m still a little confused.
Also, thank you so much for the help. You’ve already made things a thousand times clearer than they were.!
I know for a fact you can have multiple ID’s in an HTML document as long as they are not the same ID… However, you cannot have more than one element with the same ID.
I am curious about your second part of the question being is this normal or are we only being asked to include multiple ID’s for test purposes??? Id like to know as well
Mainly for testing. They are easier to deal with, at least as long as people remember to only use one of each id (i.e. ids with unique values). If you add the same id more times the test will just grab the one that comes first in the document.
It is fairly well established that using ids for styling is a bad idea. You don’t need them and they just cause issues in the long run. I personally see absolutely no reason to use them for CSS.
thank you for clarifying!!!
I was sitting there scratching my head like “I don’t understand why it’s only testing me on id’s!!” I didn’t realize it’s just so the “machine” could see that you were giving the correct code.
rookie mistake but now it all makes sense and I’m not longer confused.
you guys are awesome, and I appreciate the help! I passed my tribute page