Hide/unhide div with button?

后端 未结 4 1063
渐次进展
渐次进展 2021-01-07 08:33
    

Welcome! Chat now!

相关标签:
4条回答
  • 2021-01-07 09:10

    Look at my example without using of JavaScript.

        <input type="checkbox" id="box"/>
        <label id="container" for="box">
            <div id="button">Chat Now</div>
            <div id="login">
                <label for="box" id="closelogin">Close</label>
                <input type="text" placeholder="Username"/>
                <p id="loginshiz">Pick a username</p>
                <button id="go">Go</button>
            </div>
        </label>
    

    and css

    #box{display: none;}
    #container #login{ display: none;}
    #box:checked + #container #login{ display: block;}
    

    Fiddle http://jsfiddle.net/LUdyb/1/

    Hope this help.

    0 讨论(0)
  • 2021-01-07 09:15

    Using javascript with the help of the button id you can make the div to be hidden by changing the css property to visible. while using jquery you can use toggle,hide,show.

    0 讨论(0)
  • 2021-01-07 09:30

    There is no way you can do this in html/css

    You can use Jquery

    $('#button').click(function() {
        $('#login').css('visibility', 'visible');
    });
    

    to close

    $('#closelogin').click(function() {
        $('#login').css('visibility', 'hidden');
    });
    

    you just need to change the ID that is #closelogin and the .css('visibility', 'hidden')

    You need to include Jquery library like this in your head or bottom of your page to make it work.

    eg:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    
    0 讨论(0)
  • 2021-01-07 09:35

    Use jQuery. No way to do it plain html/css.

    $('#button').click(function() {
        $('#login').css('visibility', 'visible');
    });
    $('#closelogin').click(function() {
        $('#login').css('visibility', 'hidden');
    });
    

    If you don't have jQuery included, use javascript:

    document.getElementById('button').onclick = function() {
        document.getElementById('login').style.visibility = 'visible';
    }
    document.getElementById('closelogin').onclick = function() {
        document.getElementById('login').style.visibility = 'hidden';
    }
    
    0 讨论(0)
提交回复
热议问题