Mix of CLASS and ID in HTML and CSS

Asked

Viewed 72 times

0

I took the test of the IFSULDESTE competition of Minas Gerais organized by the CEFET-MG Foundation and I have doubts about the following question:

8 - Consider the code of the following HTML page.
inserir a descrição da imagem aqui

It is correct to state that the text color of the element <strong> of the above code is
a) red.
b) Gray.
c) rebeccapurple.
d) darkgoldenrod.
e) cornfl owerblue.

Why, according to the feedback, the letter E is the correct option? I didn’t understand this mixture of CLASS and ID. I marked the letter A.

Source: CEFET Foundation. Available at: https://concurso.fundacaocefetminas.org.br/documentos/InformticaBomSucesso41637000719030930238.pdf. Accessed in: 31 Jul 2019.

  • It doesn’t. I think it’s Strong, but you’re right, I should have specified it. I can go in on appeal.

  • @Vitor Carnaval, you edited the question specifying the element Strong, but the original question does not say.

  • The link you passed says yes, element Strong

  • Oh yes, you’re right

  • Option C and option E have the same weight, but the option is won simply because it is the rule that comes last. If you put the CSS of the letter C after the letter E vc will see that it is he that is worth.

  • Take a look at this article: https://medium.com/emanuelg-blog/understanding-a-preced%C3%Aancia-de-estilo-em-css-specificity-Heran%C3%A7a-e-cascade-effect-a437c4929173

Show 1 more comment

2 answers

2


The correct answer is the "E" alternative. No CSS, when using # in front, it’s because it’s using Id, and not class. In this case he is using the Id ""father, and the Id "son", making the attribute specific, and the more specific it is, but "strong" it will be in relation to others, so it has greater importance than other attributes.

1

CLASS and ID are different things. ID is unique per page, CLASS can have several. It was mixed several precisely to confuse, because it is a proof. And one code overwrites the other. All would work, if only 1 of the CSS codes existed. (Of course BODY would put color for everything, and the other functions only for id="sid").

So the only reason several of them show up like this is because it’s a test, because only one of them would already work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.