元素的显示与隐藏 display、visibility、overflow
在CSS中有三个显示和隐藏的单词比较常见,我们要区分开,他们分别是 display、visibility 和 overflow。
display: none;隐藏某个元素 不保留位置
display: block 显示某个元素
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> div { width: 200px; height: 100px; background-color: pink; display: none;/* display: none隐藏某个元素,不保留位置;display: block显示某个元素 */ } p { width: 200px; height: 100px; background-color: red; } </style> </head> <body> <div></div> <p>测试</p> </body> </html>