简体   繁体   English

用iPhone覆盖@media CSS

[英]Overriding @media CSS with the iPhone

The issue I'm encountering is text gets cut off in this HTML email on Android (4.0 with Samsung Galaxy). 我遇到的问题是Android(Samsung Galaxy 4.0)的HTML电子邮件中文本被截断。

I've used @media queries to address this, but they adversely affect the iPhone, scaling down the width too much. 我已经使用@media查询来解决此问题,但它们会对iPhone产生不利影响,从而导致宽度缩小太多。 I'm trying to cancel out the width: 300px !important; 我正在尝试取消width: 300px !important; just for the iPhone with no luck. 仅适用于没有运气的iPhone。

Thanks in advance for any suggestions. 在此先感谢您的任何建议。

Current @Media: @Media当前:

@media only screen and (-webkit-device-pixel-ratio: .75) {
  /* CSS for Low-density screens goes here *
   * Ex: HTC Evo, HTC Incredible, Nexus One */
   /* Styles */
      table[class="table"], td[class="cell"] {

width: 300px !important;
}
}

@media only screen and (-webkit-device-pixel-ratio: 1) and (max-device-width: 768px) {
  /* CSS for Medium-density screens goes here *
   * Ex: Samsung Ace, Kindle Fire, Macbook Pro *
   * max-device-width added so you don't target laptops and desktops */
   /* Styles */
      table[class="table"], td[class="cell"] {
width: 300px !important;

}
}


/* iPhone 4 ----------- */
    @media
    only screen and (-webkit-min-device-pixel-ratio : 1.5),
    only screen and (min-device-pixel-ratio : 1.5) {
      table[class="table"], td[class="cell"] {
          width:auto !important;
}

}

Without Media query Android text gets cut off: 如果没有媒体查询,Android文本将被截断:

没有媒体查询,Android文本将被截断

Media query also shrinks the width of td/table to 300px on the iPhone adversely affecting its display 媒体查询还将iPhone上的td / table的宽度缩小到300px,从而不利于其显示

通过媒体查询,iPhone将td / table的宽度缩小到300px

Make sure your CSS definition that you want to be applied is more specific; 确保要应用的CSS定义更具体;

@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
    .container table[class="table"], .table td[class="cell"] {
        width: auto !important;
    }
}

Where .container is a hypothetical container. 其中.container是假设的容器。

As the alternative to "-webkit-min-device-pixel-ratio: 1.5" I suspect you want "-webkit-max-device-pixel-ratio: 1". 作为“ -webkit-最小设备像素比:1.5”的替代,我怀疑您想要“ -webkit-最大设备像素比:1”。 I don't know what browsers will do with Media Queries that are neither "min-" nor "max-" (such as "-webkit-device-pixel-ratio: 1"); 我不知道浏览器将如何处理既不是“ min-”也不是“ max-”的媒体查询(例如“ -webkit-device-pixel-ratio:1”); I suspect some browsers will interpret the Media Query to mean equality, but many will just barf and always say the query was false. 我怀疑某些浏览器会将“媒体查询”解释为均等,但许多浏览器只会断断续续,总是说查询是错误的。

Does your browser perchance put error messages about Media Queries it doesn't understand into the "Error Console"? 您的浏览器性能是否将有关其无法理解的媒体查询的错误消息放入“错误控制台”?

The case of a handheld device reporting density 1 but a very large width like 800 (the "viewport" width) will sometimes occur. 手持设备报告密度为1,但有时会出现非常大的宽度(如800)(“视口”宽度)的情况。 Your current code seems to send no CSS to such devices, which I doubt is what you intend. 您当前的代码似乎没有向此类设备发送CSS,我怀疑这是您的意图。 Having a particular Media Query (such as max-device-width:) on some parts of your CSS but not others is often a hint some edge cases aren't being considered. 在CSS的某些部分(而不是其他部分)上进行特定的媒体查询(例如max-device-width :)通常暗示未考虑某些边缘情况。

try playing with max-width and min-width , to satisfy both androids and iphones. 尝试使用max-widthmin-width来满足Android和iPhone的需求。 It worked for me. 它为我工作。

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

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