1

I am making a web page with loading on load-on so when the loading times out and the <div> shows. But I am having a bit of trouble with the .style.display = 'visible' and I cannot find anything on the opposite of display = 'none'. So I am just wondering what is the opposite of 'none' in JS

3
  • 2
    There is no "opposite". All the other valid values (block, inline, default, etc) will make the element visible. Commented May 1, 2020 at 0:21
  • 1
    there is also the visible style. If you set this to false, the element will take up space but will not be drawn. Obviously, the opposite of visible=false is visible = true or just removing the attribute Commented May 1, 2020 at 0:23
  • developer.mozilla.org/en-US/docs/Web/CSS/initial
    – Phix
    Commented May 1, 2020 at 0:25

7 Answers 7

2

The answer James posted above is good and I just wanted to elaborate on the values for the display property.

The main values applicable to almost all elements for their display property are block/ inline (there is a small exception like table specific properties).

Certain HTML elements are meant to be rendered on the page as block level elements (think of <div>, <p>, <h1> etc), while other elements are naturally meant to sit along-side other elements (think of <span> <img> etc). Another way of thinking for me is that block level are vertical positioned & inline is horizontal.

So, coming round to the answer, the opposite of display: none can be either display: block / display: inline, depending upon the element. I would categorise block & inline as more of opposite of each other in the layout system. However, that may be thinking in a different context.

1
  • there is also table elements, it can be table/ table-row/ table-cell Commented May 1, 2020 at 0:54
1

If you are just trying to hide the the loading thing, you use use visibility: visible and visibility: hidden

1

If you're using javascript to set the style, the easiest solution is to set an empty display property (.style.display = '';) to undo the hiding:

const text = document.getElementById('text-element');

function hide() {
  text.style.display = 'none';
}

function show() {
  text.style.display = '';
}
div {
  height: 30px;
}
<div>
  <span id="text-element">Text</span>
</div>

<div>
  <button onclick="hide()">
    Hide Text
  </button>

  <button onclick="show()">
    Show Text
  </button>
</div>

1

If you want to retain the styling of the element, you could use .style.display=""

Using ="block" or ="inline" will disrupt your current style.

0

I would say it depends on which container you are using, it is like saying 'what is the opposite of an invisible living creature.'

Default display types for html elements

The opposite of display: none; for elements like <div> <p> <h1> <h2> ... I would say is display: block;.

But then for elements like <a> <img> <span> I would say the opposite would be display: inline;

0

There is no "display: visible"

in Jquery you can use .show() and .hide() but in pure vanilla it's understood that any other kind of display besides "none" will show the DOM element.

ej. display: block, grid, flex, inline, etc.

-1

In JavaScript you can use most of display properties that are available in CSS. Opposite to display="none"

are all the rest of display properties and are used in different situations.

My favorites are:

display:table;

combined with margin: auto; it aligns child element to the centre very well in most of the situations.

display: inline;

Displays an element as an inline element like div. Any height and width properties will have no effect

display:contents

Makes the container disappear, making the child elements children of the element the next level up in the DOM

3
  • These are not the "opposite" of display: none. The default behavior of any DOM element is display: block, this would be the default opposite of display: none. Commented May 1, 2020 at 8:57
  • 1
    @AlexisPhilip the default behavior of any DOM element (also called the initial value) is inline not block (drafts.csswg.org/css-display/#the-display-properties) Commented May 1, 2020 at 10:41
  • @Temani Afif you are right, my mistake. Most elements are either inline or block as said here. Commented May 1, 2020 at 11:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.