Getting Started with the React Hooks API

Getting Started with the React Hooks API ishadeed.com3 months ago in #Silicon Valley Love55

In CSS, we can have control over an element when its content is too big to fit in. The property for that is overflow, which is a shorthand for overflow-x and overflow-y properties. For this article, I will give an introduction to those properties, and then we will dive together into some concepts and use-cases that are related to overflow. Are you ready? Let’s dive in! Introduction To use the overflow property, we need to be sure that the element we’re applying it to has the following: Block-level element (eg: div, section) with a height set via height or max-height. By set height, I mean that the item should have content (not empty), not to add an explicit height. Or an element with white-space set to nowrap. Possible Keywords For Overflow The overflow property can accept the following possible values: visible, hidden, scroll, auto .element { height: 200px; overflow: [overflow-x] [overflow-y]; } Since overflow is a short hand property, it can accept one or two values. The first value is for the horizontal axis, and the second one is for the vertical axis. Visible The default value, where the content can extend beyond its parent. It can be set like: .element { height: 200px; overflow: visible; } An interesting fact that you should know is that when one axis is set to visible, and another axis is set to auto, the axis with visible will compute to the auto keyword. According to Mozilla Developer Network MDN: Setting one axis to visible (the default) while setting the other to a different value results in visible behaving as auto. For example, if we set an element with the following: .element { height: 200px; overflow: visible auto; } The overflow property computed value will be auto auto. Hidden When content is longer than its parent, it will be clipped. However, the content can be scrolled by using Javascript. Scroll The scroll value Allows scrolling to reveal the clipped content, and it can be horizontal or vertical. In the figure above, the scrollbar is always visible regardless if the content is long or not. Note that this depends on the operating system. Auto I consider this a smart keyword! It shows the scrollbar only if the content is longer than its container. Notice that in the figure, the scrollbar is only visible in case the content is longer than its container. Next, we will go through the longhand properties that are related to overflow. overflow-x This is responsible for the x-axis, or the horizontal sides of an element. overflow-y This is responsible for the y-axis, or the vertical sides of an element. Use Cases and Examples Simple Slider We can create a quick and simple slider by clipping the content horizontally and allowing it to scroll. In the mockup above, we have cards that laid out horizontally, and there is a scrollbar that allows us to scroll and reveal more content. To implement that, we will need to do the following: Display the cards in the same line. I will use flexbox for that. Add overflow-x to the container. .wrapper { display: flex; overflow-x: auto; } And it works on desktop browsers. However, while testing this on Safari for iOS (12.4.1),  » Read More

Like to keep reading?

This article first appeared on If you'd like to keep reading, follow the white rabbit.

View Full Article

Leave a Reply