CSS显示之间的差异:无;和可见性:隐藏;
CSS显示:无;
display:none属性用于隐藏元素而不删除它们。它不占用任何空间。
<!DOCTYPE html> <html> <head> <style> h3 { display: none; } </style> </head> <body> <h2>This heading is visible</h2> <h3>This is a hidden heading</h3> <p>The hidden heading does not take up space even after hiding it since we have used display: none;.</p> </body> </html>
CSS可见性:隐藏;
可见性:hidden属性也隐藏元素,但会影响布局,即占用空间。让我们看一个例子
<!DOCTYPE html> <html> <head> <style> h3 { visibility: hidden; } </style> </head> <body> <h2>This heading is visible</h2> <h3>This is a hidden heading</h3> <p>The hidden heading takes up space even after hiding it.</p> </body> </html>