“Collapsible”

前端 未结 2 1937
名媛妹妹
名媛妹妹 2021-02-10 23:19

I\'m having some trouble with a that I\'m trying to keep hidden, until the user clicks on a element.

The HTML looks like:

相关标签:
2条回答
  • 2021-02-11 00:03

    Is this what you want...?

    Style:

    .filter-type {
      border-bottom: 1px dotted #666;
     }
    

    HTML :

     <h3 class="filter-type">BRAND</h3>
     <p onclick="this.innerHTML='<div><ul><li>item 1</li><li>item 2</li><li>item 3</li></ul></div>'">Click Here</p>
    
    0 讨论(0)
  • 2021-02-11 00:16

    Your sidebarlistscroll DIV come after the H3 not inside H3. Write like this:

    .filter-type:active + .sidebarlistscroll {
        visibility: visible;
    }
    

    If you want the div to remain visible after when you stopped clicking on it. Then you have to do some changes in your code. Write like this :

    <label class="filter-type" for="filter">BRAND</label>
    <input type="checkbox" id="filter">
    <div class="sidebarlistscroll">
        <ul>
            <li>item 1</li>
            <li>item 2</li>
            <li>item 3</li>
        </ul>
    </div>
    

    CSS

    .filter-type {
        border-bottom: 1px dotted #666;
    }
    
    .sidebarlistscroll {
        width: 220px;
        height: 200px;
        margin-bottom: 15px;
        overflow-y: scroll;
        border: none;
        visibility: hidden;
    }
    #filter{display:none}
    #filter:checked + .sidebarlistscroll{
        visibility: visible;
    }
    

    Check this http://jsfiddle.net/BU4Qt/

    0 讨论(0)
提交回复
热议问题