0

I have set of divs as listed below,

<div id="invoice"></div>
<div id="claim"></div>
<div id="draft"></div>

and i have a reponse which may have type as invoice, claim or draft. If I get "draft" in the response then I will display only claim div and rest two will be hidden, but the problem is the above two divs are hidden and occupying space also (i.e., leaving a gap from the top and then displaying the draft div).

I am using CSS as below,

 $("#draft").css('flex','flex-wrap'); // for showing the content in a straight line.
 $("#draft").css('display','block');

and for hiding it,

 $("#draft").css('display','none');

Similarly for all the id. I am new to this, so please correct me if I am wrong somewhere. Thanks in advance.

Onera
  • 687
  • 3
  • 14
  • 34
  • 3
    Using display:none, there is no space being taken up - if you use visibility:hidden, there is. In this case it is the flex that is breaking it: http://stackoverflow.com/questions/27144702/how-to-reset-display-property-for-flex-item – mplungjan Jan 09 '17 at 13:00
  • I am not sure how display:none is occupying space... – epascarello Jan 09 '17 at 14:29

2 Answers2

1

if i understand your question below answer might be helpful.

div {
  width: 40px;
  height: 80px;
}
div.anyOne:empty {
  display: none
}
Div which has some data will be visible
<br/>
<br/>
<div id="invoice" class="anyOne">Invoice</div>
<div id="claim" class="anyOne"></div>
<div id="draft" class="anyOne"></div>
Shrijan Tiwari
  • 673
  • 6
  • 17
0

Use display: none; to hide an element completely and leaving its space.

Use visiblity: hidden to hide an element while leaving the space where it would have been.

div{
  background-color:red;
  width: 150px;
  height: 50px;
  border: solid 1px black;
}

#draft {
    display: none;
}
<div id="invoice">invoice</div>
<div id="claim">claim</div>
<div id="draft">draft</div>
<div id="another">another</div>
GibboK
  • 71,848
  • 143
  • 435
  • 658