Câu hỏi phỏng vấn CSS
Câu hỏi

What is the difference between classe s and ID s in CSS?

Câu trả lời

In CSS, classes and IDs are both selectors used to apply styles to HTML elements, but they have different purposes and use cases.

Classes

  • General Purpose: Classes are used to define a style for a group of elements. They are not unique, meaning the same class can be applied to multiple elements within the same HTML document.
  • Syntax: In CSS, a class is denoted by a period (.) followed by the class name, for example, .classname.
  • Multiple Classes: An HTML element can have multiple classes, allowing it to inherit styles from various class definitions.
  • Case Sensitivity: Class names are case-sensitive.
  • Use Case: Classes are ideal when you want to apply the same style to several elements or when you want elements to share a common style base with the flexibility to add more specific styles through additional classes or other selectors.

IDs

  • Unique Identifier: An ID is a unique identifier for a single element in an HTML document. Each ID must be unique within the document.
  • Syntax: In CSS, an ID is denoted by a hash (#) followed by the ID name, for example, #idname.
  • Single Use: An ID should only be used once per page. It is meant to select a specific element when a unique style or a JavaScript interaction is required.
  • Specificity: IDs have a higher specificity compared to...
junior

junior

Gợi ý câu hỏi phỏng vấn

middle

Explain the usage of table-layout property

entry

Explain the three main ways to apply CSS styles to a web page

middle

What does Accessibility (a11y) mean?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào