CSS CSS Tutorial CSS Advanced CSS Responsive Web Design(RWD) CSS Grid CSS Properties Sass Tutorial Sass Functions



align-self

CSS is a powerful tool for designing and styling web pages. It provides a wide range of properties that can be used to control the layout and appearance of elements on a page. One such property is align-self, which is used to align individual flex items within a flex container.

Flexbox is a layout model that allows elements to be arranged in a flexible and responsive way. It consists of a flex container and one or more flex items. The flex container is the parent element that contains the flex items. The align-self property is used to align individual flex items within the flex container.

The align-self property is a sub-property of the align-items property. It allows you to override the align-items property for individual flex items. The align-items property is used to align all flex items within the flex container. The align-self property, on the other hand, is used to align individual flex items within the flex container.

The align-self property can take the following values:

  • auto
  • flex-start
  • flex-end
  • center
  • baseline
  • stretch

The default value of align-self is auto, which means that the element inherits the value of the align-items property from its parent element. If the parent element does not have an align-items property, the default value of align-items is stretch.

Here are some examples of how to use the align-self property:

Example 1: align-self: flex-start;

In this example, the align-self property is set to flex-start. This aligns the element to the start of the flex container.

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

    .flex-item {
      align-self: flex-start;
    }
  

Example 2: align-self: flex-end;

In this example, the align-self property is set to flex-end. This aligns the element to the end of the flex container.

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

    .flex-item {
      align-self: flex-end;
    }
  

Example 3: align-self: center;

In this example, the align-self property is set to center. This aligns the element to the center of the flex container.

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

    .flex-item {
      align-self: center;
    }
  

Example 4: align-self: baseline;

In this example, the align-self property is set to baseline. This aligns the element to the baseline of the flex container.

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

    .flex-item {
      align-self: baseline;
    }
  

Example 5: align-self: stretch;

In this example, the align-self property is set to stretch. This stretches the element to fill the entire height of the flex container.

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

    .flex-item {
      align-self: stretch;
    }
  

The align-self property is a powerful tool for controlling the layout and appearance of elements within a flex container. It allows you to override the align-items property for individual flex items, giving you greater control over the layout of your web pages.

References:

Activity