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

22 Vue optimization tips (project practical)

Table of contents Code Optimization Using key in ...

Solve the problem of docker log mounting

The key is that the local server does not have wr...

Summary of 11 common mistakes made by MySQL call novices

Preface You may often receive warning emails from...

The w3c organization gives style recommendations for html4

This is the style recommendation given by the W3C ...

Tips for viewing History records and adding timestamps in Linux

Tips for viewing History records and adding times...

Methods and steps to access Baidu Maps API with JavaScript

Table of contents 1. Baidu Map API Access 2. Usin...

js to implement a simple bullet screen system

This article shares the specific code of native j...

Solve MySQL login error: 'Access denied for user 'root'@'localhost'

First of all, I don't know why I can't lo...

Detailed example code of mysql batch insert loop

background A few days ago, when I was doing pagin...

A brief discussion on VUE uni-app's commonly used APIs

Table of contents 1. Routing and page jump 2. Int...

How to convert a string into a number in JavaScript

Table of contents 1.parseInt(string, radix) 2. Nu...

Apply provide and inject to refresh Vue page method

Table of contents Method 1: Call the function dir...

Detailed steps to install CentOS7 system on VMWare virtual machine

Pre-installation work: Make sure vmware workstati...