Deep understanding of CSS overflow-small match's blue ideal

Source: Internet
Author: User
Deep understanding of CSS overflow-small match's blue ideal

* Directory [1] defines [2] attributes [3] invalid [4] applications

Previous

When an element is fixed to a specific size, the content cannot be placed in the element. In this case, you can use the overflow attribute to control this situation.

Definition

Overflow

Value: visible | hidden | scroll | auto | inherit

Initial Value: visible

Applies to: block-level elements, replacement elements, and table cells.

Inheritance: None

[Note] Except for IE7, other browsers do not support setting the overflow attribute for the table-cell element. Firefox and IE11 Browsers Do not support setting the overflow attribute for sub-elements with a height of 100% for the table-cell element.

Overflow-X | overflow-y

The attributes of overflow-x and overflow-y were originally extended by IE browser, and were later adopted and standardized by css3. Overflow-x is mainly used to define the cut for horizontal content overflow, while overflow-y is mainly used to define the cut for vertical content overflow.

[Note] If the overflow-x and overflow-y values are the same, they are equivalent to overflow. If the value of overflow-x is different from that of overflow-y, and one of the values is explicitly set to visible or the default value is visvisible, the other value is non-visvisible. The visvisible value is reset to auto

Value: visible | hidden | scroll | auto | inherit | no-display | no-content

Initial Value: visible

Applies to: block-level elements, replacement elements, and table cells.

Inheritance: None

Attribute

Visible

The content of the element is also visible outside the element box.

[NOTE 1] IE6-the inclusion block of the element in the browser will extend, so that the excess content can be wrapped.

.box{    height: 200px;    width: 200px;    background-color: lightgreen;}.in{    width: 300px;    height: 100px;    background-color: lightblue;}

The picture on the left is IE6-browser, and the picture on the right is other browsers.

[NOTE 2] IE7-browser buttons (includingAndThere are bugs. When there are more text on the button, the larger the padding on both sides of the button. You can solve this problem by setting overflow: visible.

The picture on the left shows the default situation, and the picture on the right shows the situation after overflow is set.

Auto

If the content is clipped, the browser displays a scroll bar to view other content.

[Note] for general browsers,AndBy default, the attributes include overflow: auto. However, IE7-different browsers have different vertical scroll bars by default. </p>

// IE7-browser html {overflow-y: scroll;} // other browsers html {overflow: auto;} // remove the default page scroll bar html {overflow: hidden ;}

Scroll

The content of the element is cropped at the boundary of the element box, but the browser displays the scroll bar to view other content.

[Note] When the firefox and IE8 + browsers overflow: scroll or auto, the padding-bottom is missing.

.box{    width: 100px;    height: 100px;    padding: 50px;    background-color: pink;    overflow:scroll;}.in{    width: 100px;    height: 200px;    background-color: lightgreen;}

The picture on the left shows the chrome browser, and the picture on the right shows the firefox browser.

Hidden

The content of the element is cropped at the boundary of the element box, and the content beyond the cropping area is invisible.

No-display

When the content overflows the container, no element is displayed, similar to the display: none attribute added to the element.

No-content

When the content overflows, the content is not displayed, similar to the visibility: hidden attribute added to the element.

[Note] no-display and no-content attributes are currently not supported by browsers.

Invalid

Absolute positioning elements are not always cropped by parent-level overflow attributes, especially when overflow locates between absolute positioning elements and their contained blocks.

[Note] fixed positioning is relative to window positioning, so fixed positioning elements cannot be tailored by all its parent element overflow attributes.

[Solution]

[1] The overflow element itself is an inclusion Block

Set position: absolute, fixed, or relative for the parent

[2] The child element of the overflow element is the inclusion block.

Add an element between the absolute positioning element and the overflow element and set position: absolute, fixed, or relative

Absolute positioning Element

Application

BFC can be triggered when overflow is set to auto, scroll, or hidden, so that overflow can implement some related applications. The detailed information about BFC is now

[1] Clear floating Effects

[Note] IE6-the browser does not clear the floating by using the overflow method. The common method to eliminate floating is

.clear{    *zoom: 1;}.clear:after{    content: '';    display: block;    clear: both;}

[2] avoid margin penetration

[Note] using the overflow attribute is only one of the many methods to avoid margin penetration. Other methods include BFC, padding, and border.

[3] two-column Adaptive Layout

[Note] scenarios with overflow attributes have obvious restrictions. The following two-column Adaptive Layout methods are commonly used:

.cell{    display: table-cell; width: 2000px;    *display: inline-block; *width:auto;}

[4] Tab

The overflow tab is mainly used for single-page applications.

  • 1
  • 2
  • 3
  • 4
1 2 3 4

body{    margin: 0;    text-align: center;}ul{    margin: 0;    padding: 0;    list-style: none;}a{    text-decoration: none;    color: inherit;}.show{    width: 100px;    height: 100px;    overflow: hidden;    border: 1px solid black;    line-height: 100px;    font-size: 40px;}    .show-in{    width: 100px;    height: 100px;}#one{    background-color: lightgreen;}#two{    background-color: lightyellow;}#three{    background-color: lightblue;}#four{    background-color: pink;}.con{    margin: 10px 0 0 10px;    width: 100px;}.con-in{    display:inline-block;    width: 16px;    line-height: 16px;    border: 1px solid black;    background-color: gray;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.