html - 媒体查询响应式设计

标签 html css

@media only screen and (min-width: 600px) {

nav ul{
    transform: translateY(0);
    box-shadow: 0 0 5px rgba(0,0,0, .7);
   transition: all .5s;
  }
 nav li{
    flex: none; 
    width: 100%;
    border-bottom: solid 1px #777;
  } 
  nav input[type="checkbox"]:checked + ul{
    transform: translateY(-100%);
    width: 100%;
    background: #999;   
  transition: all .5s;
  }
  nav label{display: block;}  
  nav input[type="checkbox"]:checked + ul li:nth-child(1){
    background: #777; 
    color: #fff;
  }  

  #css-toggle-menu{
  float:right;
  margin: 10px;
  }

}




/*Desktop*/


@media (min-width: 961px) and (max-width: 2000px) {
nav{

float:left; 
color:white;



}



nav ul li.active a {
 background-color: none;
  color: white;
  text-decoration:none;
 }
  a:hover {

  color:black;
  background-color:#00E3FF;

  }



nav ul li a:visited {
color:black;
text-decoration:none;   
}

}

<header>
   <nav>
     <input type="checkbox" id="css-toggle-menu" name="css-toggle-menu"> 
     <ul class="main">
           <li><a class="space" href="">Home</a></li>
           <li><a class="space" href="">Programs</a></li>
           <li><a class="space" href="">Assignments</a></li>
           <li><a class="space" href="">Enroll</a></li>
           <li><a class="space" href="">Contact</a></li>

     </ul> 
     <label for="css-toggle-menu" id="css-toggle-menu"></label> 
   </nav>
</header>





对于媒体查询,我认为在平板电脑和台式机中进行设置时,一旦达到这些参数,当切换到台式机时,平板电脑等其他布局就会消失。但是,我遇到了一个问题,当我从平板电脑模式切换到桌面时,我的手机和平板电脑屏幕上的导航栏被带到了桌面上。在桌面上,我只想在页面顶部放置一个水平导航。我没有将任何CSS放入平板电脑的导航栏中,所以我不知道如何在台式机中覆盖它。在理解媒体查询问题方面,我真的可以使用一些帮助。谢谢!

这是一个JsFiddle:https://jsfiddle.net/ma28j5kd/
(我知道小提琴并不漂亮,所以我先向您道歉)

HTML:

<header>
   <nav>
     <input type="checkbox" id="css-toggle-menu" name="css-toggle-menu"> 
     <ul class="main">
           <li><a class="space" href="">Home</a></li>
           <li><a class="space" href="">Programs</a></li>
           <li><a class="space" href="">Assignments</a></li>
           <li><a class="space" href="">Enroll</a></li>
           <li><a class="space" href="">Contact</a></li>

     </ul> 
     <label for="css-toggle-menu" id="css-toggle-menu"></label> 
   </nav>
</header>


CSS:

片剂:

@media only screen and (min-width: 600px) {

nav ul{
    transform: translateY(0);
    box-shadow: 0 0 5px rgba(0,0,0, .7);
   transition: all .5s;
  }
 nav li{
    flex: none; 
    width: 100%;
    border-bottom: solid 1px #777;
  } 
  nav input[type="checkbox"]:checked + ul{
    transform: translateY(-100%);
    width: 100%;
    background: #999;   
  transition: all .5s;
  }
  nav label{display: block;}  
  nav input[type="checkbox"]:checked + ul li:nth-child(1){
    background: #777; 
    color: #fff;
  }  

  #css-toggle-menu{
  float:right;
  margin: 10px;
  }

}


桌面:

@media (min-width: 961px) and (max-width: 2000px) {
nav{

float:left; 
color:white;



}



nav ul li.active a {
 background-color: none;
  color: white;
  text-decoration:none;
 }
  a:hover {

  color:black;
  background-color:#00E3FF;

  }



nav ul li a:visited {
color:black;
text-decoration:none;   
}

}

最佳答案

我所做的是在特定媒体查询时重新获得样式。



/* smartphones, iPhone, portrait 480x320 phones */ 
@media (min-width:321px) and (max-width: 480px) {
	.image-display { display: block; }
}

/* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
@media (min-width:481px) and (max-width: 640px) {  
	.image-display { display: none; }
}

关于html - 媒体查询响应式设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40710132/

相关文章:

css - 移动版中的 Bootstrap 列

html - 覆盖现有样式并将其移动到子元素的样式

javascript - 在 Grails 中引用 CSS 文件和 JS 文件 - twitter-bootstrap

html - CSS3 : Creating a vertical nav that is rotated 270deg

javascript - 追加后如何删除文档片段中的元素

html - 用于缩放的响应式图像高度和宽度百分比?

javascript - 滚动时触摸的 CSS 或 Javascript 事件

html - 将事件状态添加到基于 css 的水平菜单而不显示子菜单

javascript - 在 chrome 中打印 div,css 不起作用

jquery - Div 上的淡入淡出循环