Web Programming HTML and CSS Fundamentals 2 — Questions and Answers
Question 1: Which CSS selector targets an element with a specific id attribute?
- .myId
- #myId (Correct answer)
- *myId
- @myId
Correct answer: #myId
The # symbol is used in CSS to select elements by their id attribute, making #myId target the element with id='myId'.
Question 2: What is the correct HTML5 doctype declaration?
- <!DOCTYPE HTML5>
- <!DOCTYPE html PUBLIC>
- <!DOCTYPE html> (Correct answer)
- <html doctype='5'>
Correct answer: <!DOCTYPE html>
The HTML5 doctype is simply <!DOCTYPE html>, which is a simplified version compared to older HTML doctypes.
Question 3: Which CSS unit is relative to the font-size of the root element?
- em
- rem (Correct answer)
- px
- vh
Correct answer: rem
The rem unit (root em) is relative to the font-size of the root <html> element, unlike em which is relative to the parent element.
Question 4: What HTML attribute makes a form input field required before submission?
- validate
- mandatory
- required (Correct answer)
- notnull
Correct answer: required
The required attribute is a boolean HTML attribute that prevents form submission if the field is empty.
Question 5: Which CSS property is used to change the text color of an element?
- text-color
- font-color
- color (Correct answer)
- foreground
Correct answer: color
The color property in CSS sets the foreground color of text content and text decorations.
Question 6: What is the purpose of the HTML <meta charset='UTF-8'> tag?
- Sets the page language
- Specifies the character encoding for the document (Correct answer)
- Defines the page author
- Sets the viewport size
Correct answer: Specifies the character encoding for the document
The charset meta tag declares the character encoding used in the HTML document, with UTF-8 supporting virtually all characters and symbols.
Which CSS selector targets an element with a specific id attribute?