【问题标题】:Media query isn't stacking columns on mobile, but is applying other styling?媒体查询不是在移动设备上堆叠列,而是应用其他样式?
【发布时间】:2018-06-08 11:46:30
【问题描述】:

我的媒体查询有点问题(我不熟悉这些,这是呈现 html 电子邮件响应式的“最安全”方式)。

我的媒体查询:

@media only screen and (max-width: 600px){
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.submitBtn {
margin: auto !important;
float: none !important;
}
td, h3, h4, .branding, .paragraph, .container {
display: block !important;
width: 100% !important;
float: none !important;
height: auto !important;
margin: auto !important;
padding: 0 !important;
text-align: center !important;
}
td {
padding-right: 5px !important;
padding-left: 5px !important;
padding-top: 10px !important;
padding-bottom: 15px !important;
}
td.branding, img.branding {
display: block !important;
text-align: center !important;
margin: 0 auto !important;
}
.branding {
padding-bottom: 10px !important;
}
.toggle {
text-align: left;
}
table.center {
text-align: center !important;
}
.display-none {
display: none !important;
}
.checkbox {
  display: block !important;
  margin: auto !important;
  max-width: 100% !important;
  float: none !important;
}
}

作为说明,我确实在头部有设备宽度的元数据。除了我有两个 td 之外,所有其他样式都在渲染,它们没有在移动设备上堆叠。

在 chrome 中,使用检查器并将其设置为响应式,它显示它们应该在移动设备上堆叠,但当我实际测试它时它们不是。

我应该堆叠的第一个模块(我放置了占位符以删除敏感数据)

<table cellpadding="0" cellspacing="0" border="0" bgcolor="#ffffff" width="100%" align="center">
    <tr>
       <td class="branding logo" width="315" align="left">Stacking image goes here
       </td>
        <td class="branding" width="315" align="right"><span class="lighter">Text & More</span> <span class="normal">Stacking text goes here</span>
        </td>
    </tr>
</table>

我应该堆叠的另一部分:

<table cellpadding="0" cellspacing="0" border="0" bgcolor="#ffffff" width="100%" align="center">
                            <tr>
                              <td class="description" align="left" width="75%">
                                <h4 class="indent padding-t"><span class="normal middle"></span></h4>
                                <p class="paragraph indent">Y
                                </p>
                              </td>
                              <td class="checkbox">
                                <input type="checkbox" id="checkbox" name="" onclick="changeValue()" value="">
                                <label class="toggle" for="checkbox"></label>
                                <input type="hidden" id="hidden" name="" checked value="">
                              </td>
                            </tr>
                          </table>

提前感谢您的帮助,如果这是一个“新手”错误,我深表歉意,因为我可以肯定它是!

【问题讨论】:

  • 不是一切都是!important。删除它们。他们不一定会让覆盖成为真正的痛苦。看起来您不是在为 “移动优先” 进行设计,并且可能正在使用表格进行布局。在移动优先设计中,默认样式应用于移动视图,而不是桌面,并根据需要进行修改以适应更大的视口。
  • @hungerstar 是的,因为它是 html 电子邮件,以确保它在所有电子邮件客户端中正确呈现,不幸的是我不得不使用表格。至于使用重要,似乎同样适用。当我删除它时,样式不适用。
  • 我认为这对于电子邮件是准确的,但对于 CSS 则不然。查看一些ZURB Email Templates CSS 我看不到很多!important

标签: css mobile responsive-design media-queries


【解决方案1】:

事实证明,我的 CSS 顺序搞砸了一切。我删除了媒体查询中的所有样式并重新组织它,它就像一个魅力!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 2020-02-15
    • 2012-10-02
    • 2020-10-03
    • 2018-05-08
    • 2016-07-25
    相关资源
    最近更新 更多