How do you create a hidden div that doesn't create a line break or horizontal space?

后端 未结 10 1157
故里飘歌
故里飘歌 2020-11-29 15:18

I want to have a hidden checkbox that doesn\'t take up any space on the screen.

If I have this:


                      
相关标签:
10条回答
  • 2020-11-29 15:38

    Since you should focus on usability and generalities in CSS, rather than use an id to point to a specific layout element (which results in huge or multiple css files) you should probably instead use a true class in your linked .css file:

    .hidden {
    visibility: hidden;
    display: none;
    }
    

    or for the minimalist:

    .hidden {
    display: none;
    }
    

    Now you can simply apply it via:

    <div class="hidden"> content </div>
    
    0 讨论(0)
  • 2020-11-29 15:40

    Show / hide by mouse click:

    <script language="javascript">
    
        function toggle() {
    
            var ele = document.getElementById("toggleText");
            var text = document.getElementById("displayText");
    
            if (ele.style.display == "block") {
    
                ele.style.display = "none";
                text.innerHTML = "show";
            }
            else {
    
                ele.style.display = "block";
                text.innerHTML = "hide";
            }
        }
    </script>
    
    <a id="displayText" href="javascript:toggle();">show</a> <== click Here
    
    <div id="toggleText" style="display: none"><h1>peek-a-boo</h1></div>
    

    Source: Here

    0 讨论(0)
  • 2020-11-29 15:43

    Use display:none;

    <div id="divCheckbox" style="display: none;">
    
    • visibility: hidden hides the element, but it still takes up space in the layout.

    • display: none removes the element completely from the document, it doesn't take up any space.

    0 讨论(0)
  • 2020-11-29 15:48

    display: none;

    This should make the element disappear and not take up any space.

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