CSS3 overflow property explained

CSS3 overflow property explained

1. Overflow

Overflow is overflow (container). When the content exceeds the container, just add the overflow attribute value to hidden to hide the part that exceeds the container.

If the content exceeds the container but you don't want it to be hidden, you can set its property value to auto;

overflow: auto attribute If the value exceeds the limit, a scroll bar will appear; if the value does not exceed the limit, no scroll bar will appear.

The scroll bar can also be set individually, for example overflow-x: hidden; overflow-y: auto; so that only the vertical scroll bar is visible. If you define the x-axis or y-axis separately, you need to set the attribute values ​​for both attributes.

Original effect:

Add overflow: hidden; attribute, effect:

As you can see, overflow:hidden will hide the part that exceeds the box, which can also be understood as cutting off.

2. Add overflow-x: hidden; overflow-y: auto properties

The properties are set to overflow-x: auto; overflow-y: hidden; the effect is exactly the opposite of the above picture, that is, the side of the scroll bar is hidden and appears at the bottom.

2. Common attribute values ​​of overflow

There are four common overflow attributes: visible, hidden, auto and scroll;

Visible is the default value of overflow, which means it exceeds the display.

Hidden means beyond hidden;

auto is automatic, that is, a scroll bar will appear if the value exceeds the limit, and no scroll bar will appear if the value does not exceed the limit.

The content will be trimmed if scroll is set, but the browser will display a scroll bar to view the remaining content.

3. Magical usage of overflow

The first usage: Solve the margin-top transmission problem

Margin-top transmission problem: The margin-top of the child element will bring down the parent element together. This can be solved by adding overflow:hidden to the parent element

The second usage: Clear the impact of floating --- collapse the height of the parent element

Universal cleaning method

overflow:hidden

clear:both

The third usage: reveal animation --- beyond hiding

Fourth usage: single-line text exceeds ellipsis

.sl{

    white-space:nowrap;/*no line break*/

    overflow:hidden;/*Exceeding hidden*/
    
    text-overflow:ellipsis;/*exceeds ellipsis*/

    width:;

}

Note that you need to set the width

The above is a detailed explanation of the CSS3: overflow property. For more information about the CSS3 overflow property, please pay attention to other related articles on 123WORDPRESS.COM!

<<:  This article will help you thoroughly understand the specific use of cgroup in Docker

>>:  Sharing of research experience on using characters instead of rounded corners and sharp corners

Recommend

Detailed explanation of where Docker saves log files

Table of contents Where are the logs stored? View...

How to update v-for in Vue

Tips: Array change method will cause v-for to upd...

Bootstrap FileInput implements image upload function

This article example shares the specific code of ...

How to Apply for Web Design Jobs

<br />Hello everyone! It’s my honor to chat ...

Detailed explanation of Vue's keyboard events

Table of contents Common key aliases Key without ...

HTML code to add quantity badge to message button

HTML code: <a onclick="goMessage();"...

Interviewers often ask questions about React's life cycle

React Lifecycle Two pictures to help you understa...

CentOS7 64-bit installation mysql graphic tutorial

Prerequisites for installing MySQL: Install CentO...

JS removeAttribute() method to delete an attribute of an element

In JavaScript, use the removeAttribute() method o...

A brief discussion on CSS blocking merging and other effects

Non-orthogonal margins When margin is used, it wi...

HTML table tag tutorial (33): cell vertical alignment attribute VALIGN

In the vertical direction, you can set the cell a...

Experience in designing a layered interface in web design

Many netizens often ask why their websites always ...

Detailed tutorial on installing Python 3.8.1 on Linux

This example takes the installation of Python 3.8...