HTML/CSS MCQ

HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 54

Multiple choice questions and answers (MCQs) on HTML/CSS to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as tags, web standards, CSS selector, objects, and more. This quiz will easily prepare anyone to pass their online test.
 
 

1. Which CSS selector targets an element with a data-id attribute?

A [data-id] {}

B #data-id {}

C .data-id {}

D data-id {}

A
The selector [data-id] targets all elements that have the data-id attribute. You can also target a specific value of the attribute, like [data-id="value"].
 

2. Which CSS selector selects all <div> elements inside an element with the ID container?

A container div {}

B #container div {}

C div #container {}

D .container div {}

B
The selector #container div {} targets all <div> elements inside the element with the ID container.
 

3. Which CSS selector targets the first child of a parent element?

A parent:first-child {}

B parent > first-child {}

C parent:first-of-type {}

D parent > :first-child {}

D
The selector :first-child targets the first child of an element. When used with >, it specifies that we are selecting the first direct child of the parent element.
 
 

4. Which CSS selector targets all <a> elements that do not have a link (no href attribute)?

A a:empty {}

B a:not([href]) {}

C a:link {}

D a[href=""] {}

B
The selector a:not([href]) selects all <a> elements that do not have the href attribute. This allows you to target links that do not point to a destination.
 

5. Which CSS selector is used to target an element that is the last child of its parent?

A parent:last-child {}

B parent > :last-child {}

C parent:last-of-type {}

D parent > :last-of-type {}

B
The selector :last-child targets the last child of a parent element. The use of > ensures that we are selecting the last direct child of the parent element.
 

6. What is the result of the following selector: input[type="text"] ?

A Select all <input> elements of type text.

B Select all <input> elements of type text.

C Select all <text> elements of type input.

D Select all <input> elements that have a text class.

A
The selector [type="text"] selects all <input> elements where the type attribute is equal to "text". This targets text fields specifically in a form.
 
 

7. Which CSS selector selects all <p> elements that are direct children of an element with the class content?

A .content > p {}

B .content p {}

C content > p {}

D p > .content {}

A
The selector .content > p {} selects only <p> elements that are direct children of the element with the class content. The > means we target direct children, not descendants at any level.
 

8. Which CSS selector targets all <input> elements with a disabled class and a disabled attribute?

A input.disabled:disabled {}

B input[disabled].disabled {}

C .disabled[disabled] {}

D input.disabled[disabled] {}

D
The selector input.disabled[disabled] targets all <input> elements that have both the disabled class and the disabled attribute. Both conditions are necessary.
 

9. Which selector targets a <p> element only if its text is in uppercase (using text-transform: uppercase in CSS)?

A p:uppercase {}

B p::uppercase {}

C p:text-transform(uppercase) {}`

D This selector does not exist.

D
There is no CSS selector that can target an element based on the text transformation (like uppercase). CSS selectors cannot target style properties applied to content, only the HTML structure.
 
 

10. Which CSS selector targets all elements with a data-* attribute that starts with "user-"?

A [data-user-*] {}

B [data-*^="user-"] {}

C [data-user^="*"] {}

D [data-*^="user"] {}

B
The selector [data-*^="user-"] targets all elements that have a data-* attribute where the value starts with “user-“. The ^ means “starts with”.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *