ITPEC IP October 2019 Question 8
A markup language specifies the character color according to the “Syntax and meaning of the markup language definition section” below. When an element (parent) contains another element (child), the child inherits the parent’s specifications, but priority is given to the child-specific specifications if the child and the parent have different values specified for the same attribute. When the text in the “Example” below is displayed according to this rule, which of the following is the appropriate display attribute for the underlined character string? Here, “<strong>character string</strong>” specifies the character string to be emphasized, for example by using bold font.
Explanation
Red characters, emphasized — the underlined text takes red from its own color2 element and keeps the emphasis of the enclosing strong element.
The underlined string sits inside three nested elements: strong (outermost), then color1, then color2. Take each attribute separately:
- •Colour:
color1specifies blue, and its childcolor2specifies red for the same attribute, so the child's own value has priority: red - •Emphasis: only
strongspecifies it, and no inner element specifies anything different, so it is inherited down to the underlined text: emphasized
Answer (b)
Why not others:
- •(a) Blue characters, emphasized — takes the colour from the parent
color1, but the childcolor2specifies its own colour, which has priority - •(c) Blue characters, not emphasized — wrong on both counts: the colour comes from
color2, and the emphasis ofstrongis inherited - •(d) Red characters, not emphasized — right colour, but
color2specifies only colour; it does not cancel the emphasis inherited fromstrong
Key rule: Inheritance works attribute by attribute: a child overrides only the attributes it specifies itself and inherits all the others, as styles cascade through nested HTML elements in CSS.
Algorithm and Programming · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official IP past-paper collection or Report an issue.