HOW TO MAKE CONTAINER CRUSH UL?

Asked

Viewed 24 times

-2

Good afternoon ! How can I make the container hide ul when the checkbox is checked? or how I can do it in another way that is simple, only with CSS

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    list-style: none;
}

.container {    
    width: 300px;
    height: 1px;
    position: absolute;
    top: 30%;
    left: 40%;
    text-align: center;
    border: solid tomato 1px;
    cursor: pointer;
    transition: .3s;
}

.container ul {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border: lime solid 1px;
    
}


#check:checked ~ .container {
    height: 100px;
}
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Document</title>

</head>
<body><input type="checkbox" id="check">
    <label for="check" class="flex">
        <h4>Click</h4>        
    </label>
    <div class="container">
        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
            <li>Item 3</li>
        </ul>
    </div>
</body>
</html>

1 answer

0

As commented by Fernando, put overflow:hidden in CSS resolves. Basically you say that the behavior of the text that is out of the div be hiding.

See working:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    list-style: none;
}

.container {    
    width: 300px;
    height: 1px;
    position: absolute;
    top: 30%;
    left: 40%;
    text-align: center;
    border: solid tomato 1px;
    cursor: pointer;
    transition: .3s;
    overflow:hidden;
}

.container ul {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border: lime solid 1px;
    
}


#check:checked ~ .container {
    height: 100px;
}
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Document</title>

</head>
<body><input type="checkbox" id="check">
    <label for="check" class="flex">
        <h4>Click</h4>        
    </label>
    <div class="container">
        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
            <li>Item 3</li>
        </ul>
    </div>
</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.