CSS (Cascading Style Sheets) is a language used for describing the presentation of a document written in HTML. It is one of the core technologies for building websites. Below are some common CSS techniques:

1. Box Model

The box model is fundamental to understanding how elements are laid out on a webpage. It consists of margins, borders, padding, and the content itself.

  • Margin: Space around the element.
  • Border: Lines around the element.
  • Padding: Space between the content and the border.
  • Content: The actual content of the element.
.element {
  margin: 10px;
  border: 2px solid black;
  padding: 5px;
  width: 100px;
  height: 100px;
}

2. Flexbox

Flexbox is a layout model that makes it easy to design complex layouts with flexibility.

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.item {
  margin: 10px;
}

3. Grid

CSS Grid is a two-dimensional layout system for the web.

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
}

.item {
  padding: 20px;
}

4. Media Queries

Media queries allow you to apply styles based on certain conditions, such as the screen size.

@media (max-width: 600px) {
  .element {
    background-color: red;
  }
}

5. CSS Preprocessors

CSS preprocessors like Sass and Less provide powerful features like variables, nesting, and mixins.

$color: blue;

.container {
  background-color: $color;
}

For more information on CSS, you can visit our CSS Tutorial.