Docsity

(Intermediate HTML & CSS) Custom Properties Knowledge Assessment Guide 2024, Exams of Computer Science

Partial preview of the text

Download (Intermediate HTML & CSS) Custom Properties Knowledge Assessment Guide 2024 and more Exams Computer Science in PDF only on Docsity!

INTERMEDIATE HTML & CSS

Custom Properties

KNOWLEDGE ASSESSMENT GUIDE

  1. Which of the following is the correct syntax to declare a custom property in CSS?
    • a) --main-color: #ff0000;
    • b) var(--main-color: #ff0000);
    • c) custom(--main-color: #ff0000);
    • d) property(--main-color: #ff0000);
    • ** Answer:** a) --main-color: #ff0000;
    • Rationale: Custom properties in CSS are declared using the -- prefix followed by the property name and value.
  2. How do you access a custom property in CSS?
    • a) --main-color
    • b) var(--main-color)
    • c) custom(--main-color)
    • d) property(--main-color)
    • ** Answer:** b) var(--main-color)
    • Rationale: Custom properties are accessed using the var() function.
  3. Which of the following is true about the scope of custom properties?
  • d) @media (min-width: property(--breakpoint))
  • ** Answer:** a) @media (min-width: var(--breakpoint))
  • Rationale: Custom properties can be used within media queries by accessing them with the var() function.

Fill-in-the-Blank Questions

  1. To declare a custom property named --primary-color with the value #3498db, you would write: __________.
  • ** Answer:** --primary-color: #3498db;
  • Rationale: Custom properties are declared using the -- prefix followed by the property name and value.
  1. To use the custom property --primary-color in a CSS rule, you would write: color: __________;.
  • ** Answer:** color: var(--primary-color);
  • Rationale: Custom properties are accessed using the var() function.
  1. Custom properties can be defined globally by using the __________ selector.
  • ** Answer:** :root
  • Rationale: The :root selector represents the document's root element and is commonly used to define global custom properties.
  1. To provide a fallback value of #000 for a custom property --text- color, you would write: color: var(--text-color, __________);.
    • ** Answer:** #000
    • Rationale: The fallback value is specified as the second argument in the var() function.
  2. Custom properties can be inherited by child elements. True or False?
    • ** Answer:** True
    • Rationale: Custom properties are inherited by default, allowing child elements to use the values defined in their parent elements.

True/False Questions

  1. Custom properties can only be used for color values.
    • ** Answer:** False
    • Rationale: Custom properties can be used for any CSS property, not just colors.
  2. The var() function can be nested within another var() function.
    • ** Answer:** True
    • Rationale: The var() function can be nested, allowing for complex value compositions.
  • ** Answer:** a) --main-padding: 10px 20px;
  • Rationale: Custom properties can include spaces without needing quotes or special characters.
  1. How can you update a custom property value using JavaScript?
  • a) element.style.setProperty('--main-color', '#ff0000');
  • b) element.style.setProperty('var(--main-color)', '#ff0000');
  • c) element.style.setProperty('custom(--main-color)', '#ff0000');
  • d) element.style.setProperty('property(--main-color)', '#ff0000');
  • ** Answer:** a) element.style.setProperty('--main-color', '#ff0000');
  • Rationale: The setProperty method is used to update custom property values in JavaScript.
  1. Which of the following is true about the var() function's fallback value?
  • a) It is mandatory to provide a fallback value.
  • b) It is optional to provide a fallback value.
  • c) The fallback value must be a custom property.
  • d) The fallback value cannot be a custom property.
  • ** Answer:** b) It is optional to provide a fallback value.
  • Rationale: Providing a fallback value in the var() function is optional but recommended for robustness.
  1. Custom properties can be used to define values for which of the following CSS properties?
    • a) color
    • b) font-size
    • c) margin
    • d) All of the above
    • ** Answer:** d) All of the above
    • Rationale: Custom properties can be used to define values for any CSS property.
  2. Which of the following is a benefit of using custom properties in CSS?
    • a) Improved maintainability
    • b) Enhanced reusability
    • c) Simplified theming
    • d) All of the above
    • ** Answer:** d) All of the above
    • Rationale: Custom properties improve maintainability, reusability, and theming in CSS by centralizing values and making them easier to manage. Multiple Choice: Which of the following statements best describes custom properties in CSS? A) They are predefined variables that cannot be changed

Rationale: Custom properties in CSS can hold various types of values, including strings, colors, and even other custom properties. Multiple Choice: Which CSS function allows you to access the value of a custom property within another property's value? A) calc() B) var() C) rgb() D) url()

Correct Answer: B) var()

Rationale: The var() function is used to insert the value of a custom property in CSS declarations. Fill-in-the-Blank: Custom properties can be inherited by child elements using the property __.

Correct Answer: inherit

Rationale: By setting custom properties to inherit, child elements can inherit the value of the custom property from their parent elements. True/False: Custom properties are not supported in all modern browsers.

Correct Answer: False

Rationale: Custom properties are widely supported in modern browsers, making them a reliable tool for front-end developers. Multiple Choice: Which CSS rule is used to update the value of a custom property dynamically? A) @custom B) @property C) @set D) @apply

Correct Answer: D) @apply

Rationale: The @apply rule is used to update the value of a custom property dynamically within CSS. Fill-in-the-Blank: Custom properties facilitate the practice of __, allowing for easier maintenance and scalability of code.

Correct Answer: modular coding

Fill-in-the-Blank: Custom properties can improve _ by centralizing style- related values.

Correct Answer: code maintainability

Rationale: Centralizing style-related values using custom properties enhances code maintainability and makes it easier to update styles across an entire project. True/False: Custom properties are designed primarily for static styling and cannot be changed dynamically.

Correct Answer: False

Rationale: Custom properties in CSS can be changed dynamically, allowing for responsive and interactive design implementations. Multiple Choice: Which CSS declaration is used to assign a fallback value to a custom property in case it is not defined? A) fallback B) !default C) !important D) unset

Correct Answer: D) unset

Rationale: The unset value can be used to assign a fallback value to a custom property if it is not defined, ensuring graceful degradation. Fill-in-the-Blank: Custom properties are a part of the CSS __ module.

Correct Answer: Variables

Rationale: Custom properties fall under the CSS Variables module, providing a way to define and reuse variables in CSS stylesheets. True/False: Custom properties must always be declared at the beginning of a stylesheet.

Correct Answer: False

Rationale: Custom properties can be defined anywhere in a stylesheet, making them flexible and versatile for organizing style-related values. Multiple Choice: Which CSS function is used to perform mathematical operations on custom property values? A) add() B) multiply()

Multiple Choice: Which symbol is used to reference a custom property within a CSS declaration? A) @ B) $ C) # D) var()

Correct Answer: D) var()

Rationale: The var() function is used to reference custom properties within CSS declarations by specifying the property name. Fill-in-the-Blank: Custom properties promote _ by allowing developers to define and reuse style values efficiently.

Correct Answer: code reusability

Rationale: Custom properties enhance code reusability in CSS by enabling developers to define values once and reuse them throughout a stylesheet.

  1. Multiple Choice: Which of the following best defines custom properties in CSS? A) Variables for storing and reusing values in CSS B) A way to target specific elements in HTML C) A method for creating animations in CSS D) An advanced form of styling text

Correct Answer: A) Variables for storing and reusing values in CSS

Rationale: Custom properties, also known as CSS variables, allow you to define reusable values in CSS.

  1. Fill in the Blank: To use a custom property in CSS, you must prefix it with ___________.

Correct Answer: var()

Rationale: Custom properties in CSS are referenced using the var() function.

  1. True/False: Custom properties can be dynamically updated using JavaScript.

Correct Answer: True

Rationale: Custom properties can be dynamically updated using JavaScript, allowing for dynamic changes in styling.

Which of the following is a valid way to update a custom property dynamically using JavaScript? A) document.updateProperty() B) element.style.setProperty() C) setCustomProperty() D) updateCustomValue()

Correct Answer: B) element.style.setProperty()

Rationale: The setProperty method allows you to dynamically update custom properties using JavaScript.

  1. Fill in the Blank: Custom properties can be inherited by ___________ elements.

Correct Answer: Descendant

Rationale: Custom properties can be inherited by descendant elements within the same document.

  1. True/False: Custom properties can be scoped to a specific CSS rule using the :root selector.

Correct Answer: True

Rationale: The :root selector is used to scope custom properties to a specific rule set.

  1. Multiple Choice: Which of the following is an advantage of using custom properties in CSS? A) Improved browser compatibility B) Increased specificity in styling C) Easier maintenance and updates D) Quicker page loading times

Correct Answer: C) Easier maintenance and updates

Rationale: Custom properties make CSS easier to maintain and update by centralizing values.

  1. Fill in the Blank: To reference a custom property in CSS, you use the _______ function.

Correct Answer: var()

Rationale: The var() function is used to reference custom properties in CSS rules.

  1. True/False: Custom properties can be defined within a media query to provide responsive styling.

Correct Answer: True

Rationale: Custom properties can be defined within media queries to create responsive designs.