
您可以在 github 仓库中找到这篇文章中的所有代码。
您可以在此处查看隐藏元素的视觉效果 - codesandbox
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>hiding elements</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="display-none">hiding elements</div>
<div id="hidden" hidden>hiding elements</div>
<div class="outside-by-absolute">hiding elements</div>
<div class="outside-by-relative">hiding elements</div>
<div class="outside-by-margin">hiding elements</div>
<div aria-hidden="true">hiding elements(for screen reader)</div>
<div class="hide-by-opacacity">hiding elements</div>
<div class="container">
<div class="hidden-element">this is hidden</div>
<div class="covering-element">covering the elements</div>
</div>
<div class="hide-by-clip">hiding elements</div>
<div class="hide-by-transform">hiding elements</div>
</body>
</html>
.display-none {
display: none;
}
.outside-by-absolute {
position: absolute;
left: -9999px;
}
.outside-by-relative {
position: relative;
left: -9999px;
}
.outside-by-margin {
margin-left: -9999px;
}
.hide-by-opacacity {
opacity: 0;
}
.container {
position: relative;
width: 200px;
height: 200px;
}
.covering-element {
position: absolute;
width: 100%;
height: 100%;
z-index: 2;
}
.hidden-element {
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
}
.hide-by-clip {
position: absolute;
width: 200px;
height: 200px;
clip: rect(0px, 0px, 0px, 0px);
}
.hide-by-transform {
transform: scale(0, 0);
}
以上就是隐藏元素 - CSS 挑战的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号