Sizing Elements and Handling Overflow in CSS Flexbox

1. Sizing Elements

1.1 Intrinsic Size

Some elements have a natural size set by default, we call it Intrinsic Size.

In the example above, the default sizes are applied to the image and paragraph elements.

1.2 Extrinsic Size

If we set a Specific Size to an element, we call an Extrinsic Size.

In the example above, a specific size was given to the image and paragraph elements.

2. Handling Overflow

2.1 CSS Overflow Property

Content overflow can be handled using the CSS

overflow

property.

The overflow property has the following values:

  1. visible
    (default) - CSS tries to avoid data loss. Hence, the 
    overflow: visible;
     is the default value for it.
  2. hidden
    - The overflow is clipped, and the rest of the content will be invisible.
  3. scroll
    - The overflow is clipped, and a scrollbar is added to see the rest of the content.
  4. auto
    - It is similar to 
    scroll
    , but it adds scrollbars only when necessary.

Try out CSS

overflow

property with different values in the below Code Playground.

2.2 overflow-x & overflow-y

There are two other CSS properties similar to

overflow

, which is used for handling in any one particular direction.

  • overflow-x
    - To handle overflow in the horizontal direction.
  • overflow-y
    - To handle overflow in the vertical direction.

3. Min & Max Sizes

3.1 Min size

The

min-height
&
min-width
CSS properties can be used to define the minimum sizes of an element.

.paragraph {
min-height: 150px;
}
CSS

3.2 Max size

The

max-height
&
max-width
CSS properties can be used to restrict the sizes of an element.

.paragraph {
min-height: 150px;
max-height: 180px;
}
CSS

3.3 Min & Max Sizes with Overflow

If the content needs a larger than maximum height, the overflowing of content can be observed.


.paragraph {
  border: 2px solid blue;
  width: 150px;
  min-height: 150px;
  max-height: 180px;
  overflow: auto;
}


4. A Note on Meta Element

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
</html>
HTML

The

meta
element is used to provide additional important information about HTML document.

  1. Name - specifies the type of meta element it is, what type of information it contains. 
    viewport
     gives instructions to browsers on how to control the page's dimensions and scaling.
  2. Content - specifies the actual meta content.

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form