隐藏元素 - CSS 挑战
您可以在 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 挑战的详细内容,更多请关注其它相关文章!