Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Within CSS what is the difference between opacity:0 and display:none? [duplicate]

Tags:

jquery

css

I am working with the jQuery fadeIn/fadeOut method and confused by exactly what it is doing. The docs state that the method affects the opacity property of the element but display:none also work to hide an element and then fade it in. Are opacity:0 and display:none the same thing? I am seeing some really choppy animations using the methods and want to understand better whats going.

like image 954
thesteve Avatar asked Dec 22 '11 02:12

thesteve


People also ask

What is the difference between opacity 0 and display none?

As you can see, whenever you need the element to disappear completely and not take up any space, you should use display: none; . If you want the element to have a transition or fade-in effect when becoming visible, you should use opacity: 0; .

What is CSS opacity?

The opacity CSS property sets the opacity of an element. Opacity is the degree to which content behind an element is hidden, and is the opposite of transparency.

What is the difference between visibility none and display none?

visibility:hidden hides the element, but it still takes up space in the layout. display:none removes the element from the document. It does not take up any space.

What does display none do in CSS?

display: none; is commonly used with JavaScript to hide and show elements without deleting and recreating them.


2 Answers

display: none lets the element disappear. Just like it isn't present. This means your layout may change.

opacity: 0 this one just makes your element invisible. It doesn't take any effect on your layout.

like image 124
arminb Avatar answered Sep 21 '22 14:09

arminb


Both cases make the element invisible, but properties are different:

  • opacity: 0 : invisible, but takes display space (affect the layout), and clickable
  • display: none : invisible, doesn't take display space, and hence not clickable

Let me add a third one that is relevant in this context:

  • visibility: hidden : invisible, takes display space, and not clickable

I have made an demo JSFiddle here: http://jsfiddle.net/sebastien_worms/tCbJD/

like image 45
sebastien.worms Avatar answered Sep 21 '22 14:09

sebastien.worms