简体   繁体   English

CSS(@media)在WebView上不起作用

[英]CSS (@media) not working on WebView

So, I have a webview which loads an online webapp. 因此,我有一个可加载在线webapp的webview。 The problem is with the CSS @media rules that are set for it to be responsive. 问题在于为响应而设置的CSS @media规则。 It appears that when using the webview, they get ignored, or the web loaded doesn't identify correctly the device screen size. 似乎在使用Web视图时,它们将被忽略,或者加载的Web无法正确识别设备屏幕尺寸。

The thing is, when I load the webapp via Android's browser, not through a WebView, works fine, loading the CSS correctly. 问题是,当我通过Android的浏览器而不是WebView加载Web应用程序时,工作正常,可以正确加载CSS。

Here it is the CSS. 这是CSS。 I know that some @media's are commented. 我知道有些@media已发表评论。

/* Portrait and Landscape */
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2) {
.login-form {
  width: 90%;
  padding-top: 5%;
  margin: 0px auto;
  text-shadow: none;}

 div.col-md-6.text-left, div.col-md-6.text-right {
      text-align: center;
 }
}

/* Portrait
@media only screen and (min-device-width: 320px)
  and (max-device-width: 480px)
  and (-webkit-min-device-pixel-ratio: 2)
  and (orientation: portrait) {
} */

/* Landscape
@media only screen
  and (min-device-width: 320px)
  and (max-device-width: 480px)
  and (-webkit-min-device-pixel-ratio: 2)
  and (orientation: landscape) {

} */

/* ----------- iPhone 5 and 5S ----------- */

/* Portrait and Landscape */
@media only screen and (min-device-width: 320px) and (max-device-width: 568px)  {
.login-form {
  width: 90%;
  padding-top: 5%;
  margin: 0px auto;
  text-shadow: none;}

   div.col-md-6.text-left, div.col-md-6.text-right {
      text-align: center;
 }
}

/* Portrait
@media only screen
  and (min-device-width: 320px)
  and (max-device-width: 568px)
  and (-webkit-min-device-pixel-ratio: 2)
  and (orientation: portrait) {
} */

/* Landscape
@media only screen
  and (min-device-width: 320px)
  and (max-device-width: 568px)
  and (-webkit-min-device-pixel-ratio: 2)
  and (orientation: landscape) {

} */

/* ----------- iPhone 6 ----------- */

/* Portrait and Landscape */
@media only screen and (min-device-width: 375px) and (max-device-width: 667px) {
.login-form {
  width: 90%;
  padding-top: 15%;
  margin: 0px auto;
  text-shadow: none;}

   div.col-md-6.text-left, div.col-md-6.text-right {
      text-align: center;
 }
}

/* Portrait
@media only screen and (min-device-width: 375px)
 and (max-device-width: 667px)
 and (-webkit-min-device-pixel-ratio: 2)
 and (orientation: portrait) {
} */

/* Landscape
@media only screen and (min-device-width: 375px)
 and (max-device-width: 667px)
 and (-webkit-min-device-pixel-ratio: 2)
 and (orientation: landscape) {
} */

/* ----------- iPhone 6+ ----------- */

/* Portrait and Landscape */
@media only screen and (min-device-width: 414px) and (max-device-width: 736px) {
.login-form {
  width: 90%;
  padding-top: 20%;
  margin: 0px auto;
  text-shadow: none;}

   div.col-md-6.text-left, div.col-md-6.text-right {
      text-align: center;
 }
}

/* Portrait
@media only screen
  and (min-device-width: 414px)
  and (max-device-width: 736px)
  and (-webkit-min-device-pixel-ratio: 3)
  and (orientation: portrait) {

} */

/* Landscape
@media only screen
  and (min-device-width: 414px)
  and (max-device-width: 736px)
  and (-webkit-min-device-pixel-ratio: 3)
  and (orientation: landscape) {
} */

/* General Landscape*/
@media (min-device-width: 415px) and (min-device-height: 737px) {
.login-form {
  width: 360px;
  padding-top: 100px;
  margin: 0px auto;
  text-shadow: none;}

 }
}

/* General Small */
@media (min-device-width: 415px) and (min-device-height: 580px) {
.login-form {
  width: 360px;
  padding-top: 35px;
  margin: 0px auto;
  text-shadow: none;}

 }
}

/* General Full HD */
@media (min-device-width: 1920px) and (min-device-height: 1080px) {
.login-form {
  width: 20%;
  padding-top: 7%;
  margin: 0px auto;
  text-shadow: none;}
}

/* General Extreme */
@media (min-device-width: 1921px) and (min-device-height: 1081px) {
.login-form {
  width: 360px;
  padding-top: 12%;
  margin: 0px auto;
  text-shadow: none;}
}

Have you checked that you have used proper meta tag for viewport. 您是否检查过是否为视口使用了适当的元标记。 It should be in head tag in your html page. 它应该在您的html页面的head标签中。

And specially check if you media queries are specific for devices. 并特别检查您的媒体查询是否特定于设备。

So for device specific just check it is like: max-device-width. 因此,对于特定于设备的设备,只需进行检查即可:max-device-width。 If it is something like that then remove device from there. 如果是这样,请从那里卸下设备。 And then run. 然后运行。

And let me know if something other than that. 让我知道是否还有其他事情。

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

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