CSS & CSS3

Cascading Style Sheets (CSS) is the backbone of modern web design, enabling developers and designers to create visually appealing and user-friendly websites. CSS controls the layout, colors, fonts, and overall presentation of a webpage.

1. What is CSS?

CSS stands for Cascading Style Sheets. It is a stylesheet language used to describe the presentation of HTML elements. CSS allows you to control how content appears on various devices and screen sizes, enabling the creation of responsive and visually engaging designs.

Key Features of CSS

  • Separation of Content and Style: Keeps HTML for structure and CSS for styling, improving maintainability.
  • Responsive Design: Adapts designs to different screen sizes and resolutions.
  • Reusability: CSS styles can be reused across multiple web pages.

2. Types of CSS

CSS can be applied to HTML in three ways:

Inline CSS

Styles are applied directly to an HTML element using the style attribute.
Example:

Internal CSS

Styles are defined within the <style> tag in the <head> section of an HTML document.
Example:

External CSS

Styles are stored in a separate file and linked to the HTML document using the <link> tag.
Example:

3. Top 10 Powerful CSS Tricks

1. Centering with Flexbox

2. Custom Shapes with Clip-Path

3. Variable Fonts

4. Responsive Typography

5. Gradient Borders

6. Text Truncation

7. Sticky Header

8. Dark Mode Toggle

9. Parallax Effect

10. Neumorphism Design

4. CSS Selectors

Selectors are patterns used to select and style elements.

1. Basic Selectors

A. Type Selector: Targets elements by their type.

B. Class Selector: Targets elements by their class name.

C. ID Selector: Targets a specific element by its ID.

2. Advanced Selectors

A. Attribute Selector: Selects elements based on attributes

B. Pseudo-classes: Target elements in a specific state (e.g., :hover, :focus)

C. Pseudo-elements: Style parts of elements (e.g., ::before, ::after)

5. CSS Box Model

The box model is the foundation of layout design in CSS. Every HTML element is considered a rectangular box consisting of:

  1. Content: The inner part where text or elements are displayed.
  2. Padding: Space between the content and the border.
  3. Border: The edge surrounding the padding.
  4. Margin: Space outside the border, separating the element from others.

6. Positioning

CSS offers multiple positioning schemes to control how elements are placed:

  • Static: Default position, follows normal document flow.
  • Relative: Positioned relative to its normal position.
  • Absolute: Positioned relative to its nearest positioned ancestor.
  • Fixed: Positioned relative to the viewport, does not move during scrolling.
  • Sticky: Toggles between relative and fixed based on scroll position.

7. Responsive Design with Media Queries

Media queries allow CSS to apply styles based on device characteristics like width, height, and orientation.

8. Animation and Transitions

CSS animations and transitions enhance interactivity and visual appeal.

A. Transitions

Transitions smoothly change property values over time.

B. Animations

Define animations using @keyframes and apply them with the animation property.

Check Out Tailwind Component Design