简体   繁体   English

@media screen and (min-width: 1280px){ 即使我的分辨率是 1920*1080 也不起作用

[英]@media screen and (min-width: 1280px){ does not work even though my resolution is 1920*1080

The Navigation menu items are not showing for 1920 * 1080 1920 * 1080 不显示导航菜单项

I set display = none for all device widths except >1280我为除 >1280 之外的所有设备宽度设置 display = none

 `@media only screen and (min-width: 100px) and (max-width: 260px) {

  header .navigation {
  display: none;
  }

  @media only screen and (min-width: 260px) and (max-width: 350px) {

  header .navigation {
  display: none;
  }



 @media only screen and (min-width: 370px) and (max-width: 500px) {
  header .navigation {
 display: none;
}


@media only screen and (min-width: 500px) and (max-width: 1280px) {
header .navigation {
display: none;
}

@media only screen and (min-width: 350px) and (max-width: 370px) {

header .navigation {
display: none;
}

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

header .navigation{

height:3em;
position: relative;
background:  dark orange ;
width:98em;
top:50;
left:-12em;
font-size:30px;
font-color: dark orange;
font-family: Meow Script;
padding:20px;
}


header .navigation .navigation-items a{

 font-family: Meow Script;
  position: relative;
  background: dark red;
  color: white;
  font-size: 3em;
  font-weight: 500;
  width:100px;
  font-size:20px;
  text-decoration: none;
  margin-left: 15px;
  transition: 0.3s ease;
  left :15em;
  padding: 15px 40px;
  border-radius:150px;
  font-family: Meow Script;
  }

  header .navigation .navigation-items a span{
  border-radius:50px;
  width:100px;
  font-family: Meow Script;
  font-size: 1.2em;
  }

  header .navigation .navigation-items a:before{
   content: '';
   position: absolute; 
   font-family: Meow Script;
   width: 0;
   height: 3px;
   bottom: 0;
   left: 0;
   transition: 0.3s ease;
  }

  header .navigation .navigation-items a:hover:before{
  width: 100%;
  }
  }`

  if I use the same in a different CSS file without media queries I am able to see the navigation menus in my Laptop 1920*  1080 resolution.

Navigation menus showing when CSS used without media Query.在没有媒体查询的情况下使用 CSS 时显示的导航菜单。 Navigation menu not showing when CSS used with media Query for 1920*1080 Laptop当 CSS 与 1920*1080 笔记本电脑的媒体查询一起使用时,导航菜单不显示

I tried to write media queries such that Navigation menu shows only >1280 px width and not for smaller screen width like mobile and Laptop.我尝试编写媒体查询,使导航菜单仅显示 >1280 像素的宽度,而不显示较小的屏幕宽度,如移动设备和笔记本电脑。

I made display = none for all device widths <1280px.我为所有设备宽度 <1280px 设置了 display = none。

But the navigation menu is not displaying for 1920*1080 as但是导航菜单不显示 1920*1080 为

well (>1280px width)很好(>1280px 宽度)

You are missing an only on the last mediaQuery .only在最后一个mediaQuery上缺少一个。

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

Should be应该

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

Start fixing some errors in your CSS, if you don't know what fix try using an online validator, like this:开始修复您的 CSS 中的一些错误,如果您不知道如何修复,请尝试使用在线验证器,如下所示:

https://jigsaw.w3.org/css-validator/#validate_by_input https://jigsaw.w3.org/css-validator/#validate_by_input

Maybe the problem is not properly on the media queries but in the output generated by other rules.也许问题不在媒体查询上,而在其他规则生成的 output 上。

Hint about media queries: put all your CSS outside the media Queries and use them only to change the desired features.关于媒体查询的提示:将所有 CSS 放在媒体查询之外,仅使用它们来更改所需的功能。 Pay attention to the order of the media queries, sometime a statement overwrite the one before.注意媒体查询的顺序,有时一条语句会覆盖之前的语句。

Try this CSS:试试这个 CSS:

header .navigation {
    display: none;
}
header .navigation {
    height: 3em;
    position: relative;
    background: darkorange;
    width: 98em;
    /* top:50;*/ /* this make the object disappear */
    /* left:-12em;*/ /* this make youtr object disappear */
    font-size: 30px;
    color: #000;
    font-family: Meow Script;
    padding: 20px;
}
header .navigation .navigation-items a {
    font-family: Meow Script;
    position: relative;
    background: darkred;
    color: white;
    font-size: 3em;
    font-weight: 500;
    width: 100px;
    font-size: 20px;
    text-decoration: none;
    margin-left: 15px;
    transition: 0.3s ease;
    left : 15em;
    padding: 15px 40px;
    border-radius: 150px;
    font-family: Meow Script;
}
header .navigation .navigation-items a span {
    border-radius: 50px;
    width: 100px;
    font-family: Meow Script;
    font-size: 1.2em;
}
header .navigation .navigation-items a:before {
    content: '';
    position: absolute;
    font-family: Meow Script;
    width: 0;
    height: 3px;
    bottom: 0;
    left: 0;
    transition: 0.3s ease;
}
header .navigation .navigation-items a:hover:before {
    width: 100%;
}
@media screen and (min-width: 1280px) {
header .navigation {
    display: block;
}
}

Working Codepen: https://codepen.io/Davevvave/pen/poZrwZE工作代码笔: https://codepen.io/Davevvave/pen/poZrwZE

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么@media被覆盖,即使我的最大高度是768px而不是1280px? - Why is @media overridden even though my max-height is 768px and not 1280px? @media屏幕和(最小宽度)不起作用 - @media screen and (min-width) does not work @media屏幕(最小宽度:1200像素)在Chrome中不起作用 - @media screen (min-width:1200px) not working in Chrome 最小宽度:1920像素无法正确触发 - min-width: 1920px not firing off correctly 仅屏幕和(最小宽度:0px)和(最大宽度:327px)不起作用 - only screen and (min-width: 0px) and (max-width: 327px) not work 媒体查询1280px时不会显示一个元素 - one element will not display at media query 1280px 为什么@media only screen and (min-width: 768px) 也适用于屏幕宽度小于768px - why @media only screen and (min-width: 768px) also apply for screen width less than 768px 使用Chrome Devtools,我的分辨率为1680px,但是最小宽度:1440px的媒体查询不起作用 - Using Chrome Devtools, I have the resolution @ 1680px, but a min-width:1440px media query is not working 对于大于 1280 像素的屏幕尺寸,我如何在页面的正文标签上强制设置边距(左右为 50 像素) - How can i force a margin (right and left to 50px) on the body tag of my page for screen sizes above 1280px 文字在@media屏幕上居中对齐,并且(min-width:992px)和(max-width:1199px) - text not aligns to centers on @media screen and (min-width:992px) and (max-width:1199px)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM