【问题标题】:How to do an animated sidebar?如何制作动画侧边栏?
【发布时间】:2022-01-26 09:16:52
【问题描述】:

我刚开始学习网页设计,想创建一个侧边栏。我在 w3school 上查找并喜欢该设计,但无法理解某些表达式,例如 .overlay 类后的 a、javascript:void(0)、@media screen 和 (max-height: 450px) 等。有人可以教我一下每个人的行都做什么?感谢您的帮助。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
  font-family: 'Lato', sans-serif;
}

.overlay {
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: rgb(0,0,0);
  background-color: rgba(0,0,0, 0.9);
  overflow-x: hidden;
  transition: 0.5s;
}

.overlay-content {
  position: relative;
  top: 25%;
  width: 100%;
  text-align: center;
  margin-top: 30px;
}

.overlay a {
  padding: 8px;
  text-decoration: none;
  font-size: 36px;
  color: #818181;
  display: block;
  transition: 0.3s;
}

.overlay a:hover, .overlay a:focus {
  color: #f1f1f1;
}

.overlay .closebtn {
  position: absolute;
  top: 20px;
  right: 45px;
  font-size: 60px;
}

@media screen and (max-height: 450px) {
  .overlay a {font-size: 20px}
  .overlay .closebtn {
  font-size: 40px;
  top: 15px;
  right: 35px;
  }
}
</style>
</head>
<body>

<div id="myNav" class="overlay">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
  <div class="overlay-content">
    <a href="#">About</a>
    <a href="#">Services</a>
    <a href="#">Clients</a>
    <a href="#">Contact</a>
  </div>
</div>

<h2>Fullscreen Overlay Nav Example</h2>
<p>Click on the element below to open the fullscreen overlay navigation menu.</p>
<p>In this example, the navigation menu will slide in, from left to right:</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; open</span>

<script>
function openNav() {
  document.getElementById("myNav").style.width = "100%";
}

function closeNav() {
  document.getElementById("myNav").style.width = "0%";
}
</script>
     
</body>
</html>

【问题讨论】:

    标签: javascript html jquery css sidebar


    【解决方案1】:

    @media screen and (max-height: 450px) 仅在浏览器窗口为 450 px 时应用指定条件

    【讨论】:

      【解决方案2】:

      好的,我会尝试一个接一个地回答你的问题

      1. .overlay-content 元素之后的&lt;a&gt; 元素是侧边栏中的链接。
      2. javascript:void(0) 向浏览器指定链接不应重定向到任何页面或重新加载当前页面。这是因为链接用于特定功能(打开和关闭侧边栏)。但是,这不是语义。如果要执行点击操作,请使用 &lt;button&gt; 元素。
      3. @media screen and (max-height: 450px) 是一个断点,包含满足条件的规则(从 0px 高度到 450px 高度)。因此,此处的所有规则仅适用于屏幕高度为 450 像素或更小的情况。

      【讨论】:

        猜你喜欢
        • 2015-10-20
        • 2019-09-19
        • 2020-08-19
        • 1970-01-01
        • 1970-01-01
        • 2021-12-15
        • 2017-05-22
        • 2015-01-18
        • 1970-01-01
        相关资源
        最近更新 更多