CSS3 modules and their usage

CSS3 modules are a set of features and specifications that extend the capabilities of CSS (Cascading Style Sheets). They allow developers to create more advanced and interactive designs for web pages. Here are some commonly used CSS3 modules and their usage:

  1. CSS3 Selectors Module:
  2. Allows you to select and style specific elements on a web page based on their attributes, classes, or relationships with other elements.
  3. Example usage: p:first-child { color: red; } - selects the first child paragraph element and sets its color to red.
  4. CSS3 Box Model Module:
  5. Defines how elements are laid out and how their dimensions are calculated.
  6. Example usage: div { width: 200px; height: 100px; padding: 10px; border: 1px solid black; } - sets the width and height of a div element, adds padding, and applies a border.
  7. CSS3 Transitions Module:
  8. Allows you to create smooth transitions between different property values over a specified duration.
  9. Example usage: button { transition: background-color 0.3s ease; } - applies a transition effect to the background color of a button element with a duration of 0.3 seconds and an easing function.
  10. CSS3 Animations Module:
  11. Enables the creation of complex animations by defining keyframes and specifying their properties.
  12. Example usage: @keyframes slide-in { 0% { transform: translateX(-100%); } 100% { transform: translateX(0); } } - defines a keyframe animation that slides an element in from the left.
  13. CSS3 Flexbox Module:
  14. Provides a flexible way to lay out elements in a container, allowing them to dynamically adjust their size and position.
  15. Example usage: div { display: flex; justify-content: center; align-items: center; } - creates a flex container and centers its child elements horizontally and vertically.

Please note that the above examples are written in CSS syntax. If you want to use JavaScript to manipulate the CSS properties dynamically, you can use the style property of HTML elements. For example:

<!DOCTYPE html>
<html>
<head>
<style>
.my-element {
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="my-element"></div>
<script>
const element = document.querySelector('.my-element');
element.style.backgroundColor = 'blue';
</script>
</body>
</html>

In the above example, the JavaScript code selects the element with the class “my-element” and changes its background color to blue.