html - 将媒体查询从最大宽度反转为最小宽度

标签 html css

基本上,我找到了一个不错的响应式导航栏,我想使用它,但它的 @media 查询设置为 max-width: 600px。我想将它设置为最小尺寸,320px 和 786px。我通常能够逆向代码以适应,但我真的坚持这个。

这是 CodePen 的链接:https://codepen.io/jo_Geek/pen/xgbaEr

和代码本身:

* {
  box-sizing: border-box;
}

body {
  margin: 0px;
  font-family: 'segoe ui';
}

.nav {
  height: 50px;
  width: 100%;
  background-color: #4d4d4d;
  position: relative;
}

.nav>.nav-header {
  display: inline;
}

.nav>.nav-header>.nav-title {
  display: inline-block;
  font-size: 22px;
  color: #fff;
  padding: 10px 10px 10px 10px;
}

.nav>.nav-btn {
  display: none;
}

.nav>.nav-links {
  display: inline;
  float: right;
  font-size: 18px;
}

.nav>.nav-links>a {
  display: inline-block;
  padding: 13px 10px 13px 10px;
  text-decoration: none;
  color: #efefef;
}

.nav>.nav-links>a:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

.nav>#nav-check {
  display: none;
}

@media (max-width:600px) {
  .nav>.nav-btn {
    display: inline-block;
    position: absolute;
    right: 0px;
    top: 0px;
  }
  .nav>.nav-btn>label {
    display: inline-block;
    width: 50px;
    height: 50px;
    padding: 13px;
  }
  .nav>.nav-btn>label:hover {
    background-color: rgba(0, 0, 0, 0.3);
  }
  .nav>.nav-btn>label>span {
    display: block;
    width: 25px;
    height: 10px;
    border-top: 2px solid #eee;
  }
  .nav>.nav-links {
    position: absolute;
    display: block;
    width: 100%;
    background-color: #333;
    height: 0px;
    transition: all 0.3s ease-in;
    overflow-y: hidden;
    top: 50px;
    left: 0px;
  }
  .nav>.nav-links>a {
    display: block;
    width: 100%;
  }
  .nav>#nav-check:not(:checked)+.nav-links {
    height: 0px;
  }
  .nav>#nav-check:checked+.nav-links {
    height: calc(100vh - 50px);
    overflow-y: auto;
  }
}
<div class="nav">
  <div class="nav-header">
    <div class="nav-title">
      JoGeek
    </div>
  </div>
  <div class="nav-btn">
    <label for="nav-check">
      <span></span>
      <span></span>
      <span></span>
    </label>
  </div>
  <input type="checkbox" id="nav-check">
  <div class="nav-links">
    <a href="//github.io/jo_geek" target="_blank">Github</a>
    <a href="http://stackoverflow.com/users/4084003/" target="_blank">Stackoverflow</a>
    <a href="https://in.linkedin.com/in/jonesvinothjoseph" target="_blank">LinkedIn</a>
    <a href="https://codepen.io/jo_Geek/" target="_blank">Codepen</a>
    <a href="https://jsfiddle.net/user/jo_Geek/" target="_blank">JsFiddle</a>
  </div>
</div>

最佳答案

你必须使用

@media (min-width: 320px) and (max-width: 786px) {

//CSS

}

关于html - 将媒体查询从最大宽度反转为最小宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55165394/

相关文章:

具有相邻类限制的css匹配选择器

jquery - fadeIn fadeOut 元素悬停在另一个元素上时,无法正常工作

css - 在 css 中列出具有不同图标的行列

html - CSS - 清除 div 时 Clearfix 不起作用

html - 如何将 CSS 中的 HTML 数据属性用作属性?

html - 使用 Flex Box 将列移动到下一行

css - 防止 SASS gulp 编译器在 "!important"之前添加空格

html - Bootstrap 和 Normalize.css : spacing problems

javascript - 如何在 Jquery Mobile 中拖动项目

javascript - 提交后如何清除文本字段值