Css sibling selector (~) does not work with checked property

Why is my css below not working for me? Can someone advise me, please.

#slide1:checked ~ #inner { margin-left: 0;}
#slide2:checked ~ #inner { margin-left: -800px;}
#slide3:checked ~ #inner { margin-left: -1600px;}

Below is the css below. I don’t know where to go from here.

#slide1:checked ~ #broadControl label:nth-child(1),
#slide2:checked ~ #broadControl label:nth-child(2),
#slide3:checked ~ #broadControl label:nth-child(3){
    background: #333;
    border-color: #333; !important;
}

HTML:

<div id="broadcast">
    <div id="overflow">
        <div id="inner">

            <article>
                <div class="info"></div>
                <div id="pic1"></div>
                <!--img src=""-->
            </article>
            <article>
                <div class="info"></div>
                <div id="pic2"></div>
                <!--img src=""-->
            </article>
            <article>
                <div class="info"></div>
                <div id="pic3"></div>
                <!--img src=""-->
            </article>

        </div>
    </div>
</div>

<!-- Broadcast controls -->
<input checked type="radio" name="slider" id="slide1">
<input type="radio" name="slider" id="slide2">
<input type="radio" name="slider" id="slide3">
<div id="broadControl">
    <label for="slide1"></label>
    <label for="slide2"></label>
    <label for="slide3"></label>
</div>

I am trying to make a slide transition with pure CSS in order to understand CSS more.

But I’ve been stuck here for 3 days.

I have no idea why this is not working.

If you have any ideas, offer them to me.

Thanks in advance.

+5
source share
1 answer
#slide1:checked ~ #broadControl label:nth-child(1)

The operator ~only works on AFTER elements. In this case #slide1, it searches for #broadControlAFTER label elements #slide1; it cannot search in front of it.

Sample script:
http://jsfiddle.net/9vxYJ/

, #broadcast broadcast controls.

, ~ - , , . , #broadcast IS , #slide1 .., #inner, :

#slide1:checked ~ #broadcast > #overflow > #inner { margin-left: 0;}
#slide2:checked ~ #broadcast > #overflow > #inner { margin-left: -800px;}
#slide3:checked ~ #broadcast > #overflow > #inner { margin-left: -1600px;}
+8

All Articles