简体   繁体   English

桌面媒体查询影响移动视图

[英]desktop media query affects the mobile view

I have a problem where I created the first mobile view and then want to add the desktop, iPad, etc... But when I do add a media query for the "desktop view (like I want to believe)" it affects the look for mobile view.我有一个问题,我创建了第一个移动视图,然后想添加桌面、iPad 等......但是当我为“桌面视图(就像我想相信)”添加媒体查询时,它会影响外观用于移动视图。 What can I do to make the breakpoint for the desktop view, but so it won't affect the mobile, screen width, and iPad.我该怎么做才能为桌面视图设置断点,但不会影响移动设备、屏幕宽度和 iPad。 *Link for the full code: https://codepen.io/schoolcoder/pen/WNEgboE *完整代码链接: https : //codepen.io/schoolcoder/pen/WNEgboE

.split {
    display: flex;
    @media screen only and (min-width:50em) {
    }
}

I added a screenshot as well;我还添加了一个屏幕截图; the end result I want and what I get when I add the code.我想要的最终结果以及添加代码时得到的结果。 If anyone has any advice, I have tried a million combinations still isn't working... Would be much appreciated!如果有人有任何建议,我已经尝试了一百万种组合仍然不起作用......将不胜感激!

The media query needs to encapsulate the rules that it applies to, not the other way around.媒体查询需要封装它适用的规则,而不是相反。

@media screen only and (min-width: 50em) {
    .split {
        display: flex;
    }
}

Hello and welcome to Stack Overflow!您好,欢迎来到 Stack Overflow!

You can set desktop screen styles normally with CSS and then add media queries for mobile view.您可以使用 CSS 正常设置桌面屏幕样式,然后为移动视图添加媒体查询。

For example, this would be your CSS for your desktop view.例如,这将是您桌面视图的 CSS。

.split {
   display: flex;
}

This would be your CSS for mobile views.这将是您用于移动视图的 CSS。

/* I recommend using pixels instead of em */
/* This would be your view on any screen smaller than 850px i.e., most mobile devices */

@media only screen and (max-width: 850px) {
   .split {
     display: flex;
  }
}

/* you can also add multiple/different class styles under one media query. ex. */

@media only screen and (max-width: 850px) {
   .split {
     display: flex;
  }
   
   .classname {
     font-size: larger;
  }
} /* <-- just be sure to close your media query */

So to recap, I would first make your page based on the desktop view and once you are comfortable with that feeling you can start resizing your browser and implement media queries to have your content adjust accordingly.所以回顾一下,我首先会根据桌面视图制作您的页面,一旦您对这种感觉感到满意,您就可以开始调整浏览器的大小并实施媒体查询以相应地调整您的内容。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM