How do you create a hidden div that doesn't create a line break or horizontal space?
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.
Hidden divs make my site too long
style="display: none"
in the css
Put buttons under each other that don't leave space when hidden
I have found how to make it work.
Instead of using
document.getElementById("button").style.visibility = 'hidden'
I have now used
document.getElementById("button").style.display = 'none'
This makes the buttons fill the gaps when they're hidden.
How do I prevent DIV tag starting a new line?
The div
tag is a block element, causing that behavior.
You should use a span
element instead, which is inline.
If you really want to use div
, add style="display: inline"
. (You can also put that in a CSS rule)
Hide some divs (it won't take space)
You need to use display:none
to hide an element completely from the layout instead, which is documented as:
none - This value causes an element to not appear in the document. It has no effect on layout.
visibility:hidden
will leave an invisible box, which is the problem you are encountering. From the documentation:
hidden - The generated box is invisible (fully transparent, nothing is drawn), but still affects layout. Furthermore, descendants of the element will be visible if they have 'visibility: visible'.
The default CSS display
value for a <div>
is display:block
, so to show the <div>
again, just set the element back to display:block
. Note that there are other values for display
, so take care to set it back to it's original value (which might not necessarily be the default value).
Related Topics
Uppercase or Lowercase Doctype
Conditional HTML Attributes Using Razor MVC3
Issue with CSS Media Queries(Scrollbar)
What Replaces Cellpadding, Cellspacing, Valign, and Align in HTML5 Tables
Can Comments Appear Before the Doctype Declaration
Manipulating External Svg File Style Properties with CSS
HTML Video Player Plays Sound But Not Video
How to Make the HTML5 Number Field Display Trailing Zeroes
Stop CSS Transition from Firing on Page Load
Why Do I Need a Doctype? (What Does It Do)
Is There a Max Size to the Length of a Hidden Input in HTML
How to Convert <Font Size="10"> to Px
How to Set a Background in a Bootstrap Column That Oversizes the Div
Html5Shiv VS Dean Edwards IE7-Js VS Modernizr - Which to Choose