18.9 C
Canberra
Sunday, February 22, 2026

CSS Cover div if interior div is empty fails on iOS/iPadOS


Be aware: this query has been considerably edited to make it extra clear what I’m asking…

I’ve a div that I need to cover if a div within it’s empty. I have been in a position to accomplish this by doing the next:

div.inside
{
    background-color: inexperienced;
    width : 100%;
    top : 100%;

    /* the magic occurs right here */
    &:has(div.inside-text:empty)
    {
        show : none;
    }
}

On iOS & iPadOS Safari (utilizing model 26.3), I discover that when the inside-text div is empty, the within div doesn’t cover. This works completely advantageous on Chrome and Firefox.

What’s the correct solution to get this to work on iOS/iPadOS?

The pattern code right here hides the within div if the checkbox is checked (which in flip units the innerHTML of the inside-text to "").

That is what it seems like unchecked:

CSS Cover div if interior div is empty fails on iOS/iPadOS

That is what it seems like on Chrome when checked:

enter image description here

That is what it seems like on the iPad (not working):

enter image description here

const checkBox1 = doc.getElementById("checkbox");
const insideDiv = doc.getElementById("inside-text");

checkBox1.addEventListener("change", perform(){
    if (this.checked) {
        insideDiv.innerHTML = "";
    } else {
        insideDiv.innerHTML = "Textual content in right here";
    }
});
physique
{
    background-color: grey;
}

div.container
{
    background-color: white;
    place : mounted;
    prime : 50%;
    left : 50%;
    width : 50%;
    top : 50%;
    remodel: translate(-50%, -50%);
    border : 1px black stable;
}

div.inside
{
    background-color: inexperienced;
    width : 100%;
    top : 100%;

    &:has(div.inside-text:empty)
    {
        show : none;
    }
}

div.inside div.inside-text
{
    background-color: pink;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Check</title>
</head>

<physique>

<enter kind="checkbox" id="checkbox"> Cover textual content in backside div. (White if checked.)

<div class="container">
    <div class="inside">
        <div class="inside-text" id="inside-text">Textual content in right here</div>
    </div>
</div>

</physique>

</html>

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles