Solution to overflow:hidden failure in CSS

Solution to overflow:hidden failure in CSS

Cause of failure

Today, when I was writing a carousel, I found that overflow;hidden; could fail. The reason is as follows: if the parent element wants to hide the overflowing absolutely positioned child elements, it needs to add a positioning to the parent element; because the absolutely positioned child elements will look for the positioned parent element from the inside to the outside, and if it can't find it, overflow:hidden; will also fail.

check it out

It is important to repeat, as mentioned above, the reason why overflow:hidden; fails is that if the parent element wants to hide the overflowing absolutely positioned child element, it needs to add a positioning to the parent element; because the absolutely positioned child element will look for the positioned parent element from the inside to the outside, and if it cannot find the parent element, overflow:hidden; will also fail.

Let's try it:

(1)

<style>
    .wrapper{
        width: 200px;
        height: 200px;
        background-color: red;
        overflow: hidden;                 
     }
     .content{
         width: 200px;
         height: 200px;
         background-color: green;
         position: absolute;
         top: 100px;
         left: 100px;
      }
</style>
<body>
     <div class="wrapper">
         <div class="content"></div>
     </div>
</body>

When the child element is absolutely positioned, it is obvious that overflow:hidden; is invalid

(2)

<style>
    .wrapper{
        width: 200px;
        height: 200px;
        background-color: red;
        overflow: hidden;      
        position: relative;           
    }
    .content{
        width: 200px;
        height: 200px;
        background-color: green;
        position: absolute;
        top: 100px;
        left: 100px;
     }
</style>
<body>
    <div class="wrapper">
        <div class="content"></div>
    </div>
</body>

We just need to add a positioning to the parent element, either absolute or relative (but note that if the positioning is absolute, the parent element will affect the elements below the y-axis), so that the absolutely positioned child element can find the parent element, and overflow:hidden; will not fail

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  How to click on the a tag to pop up the input file upload dialog box

>>:  User experience analysis of facebook dating website design

Recommend

Summary of all HTML interview questions

1. The role of doctype, the difference between st...

js to realize payment countdown and return to the home page

Payment countdown to return to the home page case...

Detailed explanation of how to use the Vue license plate input component

A simple license plate input component (vue) for ...

A brief discussion on tags in HTML

0. What is a tag? XML/HTML CodeCopy content to cl...

A brief discussion of the interesting box model of CSS3 box-sizing property

Everyone must know the composition of the box mod...

How to enable slow query log in MySQL

1.1 Introduction By enabling the slow query log, ...

Detailed explanation of the usage of Object.assign() in ES6

Table of contents 2. Purpose 2.1 Adding propertie...

Steps to build MHA architecture deployment in MySQL

Table of contents MAH 1. Introduction to MAH Arch...

Ubuntu starts the SSH service remote login operation

ssh-secure shell, provides secure remote login. W...

Front-end development must learn to understand HTML tags every day (1)

2.1 Semanticization makes your web pages better u...

How to use Flex layout to achieve scrolling of fixed content area in the head

The fixed layout of the page header was previousl...

Common tags in XHTML

What are XHTML tags? XHTML tag elements are the b...

Detailed explanation of Docker Volume permission management

Volume data volume is an important concept of Doc...

Complete Tutorial on Deploying Java Web Project on Linux Server

Most of this article refers to other tutorials on...