【问题标题】:Table Stacking and Resizing with HTML and CSS使用 HTML 和 CSS 进行表格堆叠和调整大小
【发布时间】:2015-01-13 17:29:52
【问题描述】:

我正在尝试使用 HTML 和 CSS 构建一个相当简单的电子邮件,其中它可以是 300px 宽或 600px 宽,具体取决于以下@media:

@media only screen and (max-width: 599px) { /* Mobiles etc */ }
@media only screen and (min-width: 600px) { /* Tablets or Desktops etc */ }

然后我有一个表,其中有两个表,一旦我将浏览器的大小调整到小于 600 像素,它们就会堆叠,这很好。我是这样做的:

  @media only screen and (max-width: 599px) {  
  .floatLeftResponse{
    width:100% !important;
    float:left;
  }

但是,我似乎无法让一切正常工作,因为我的整个电子邮件要么由一个 600 像素宽的表格组成,要么由两个 50% 宽的表格组成。在某些情况下,我希望右侧在左侧之上,反之亦然。

然后我们有 600px 宽的图像,它也应该缩小到 300px 宽。

由于我对这一切还很陌生,所以我一直在进行大量的谷歌搜索,每次我让一个部分工作时,我都会设法破坏其他部分。任何帮助将不胜感激:)

【问题讨论】:

  • 仅供参考,很多电子邮件客户do not support media queries
  • @jlego,我应该用什么来让我的电子邮件“响应”?
  • 您可以将媒体查询用于支持它的媒体查询,只要您知道它们不像 Web 浏览器那样支持跨客户端。 Litmus、Campaign Monitor 和 MailChimp 都有关于这方面最佳实践的文章和资源。
  • 你的桌子有边框吗?你可以设置一个 JSFiddle 吗?
  • @jlego,我的桌子没有任何边框。以前没有听说过 JSFiddle,但今晚会玩。我希望它在移动设备(Android/Apple)等较小的设备上切换到 300 像素宽,在平板电脑/PC 上切换到正常的 600 像素宽……如果不是@media,该怎么办?

标签: html css media-queries scaling


【解决方案1】:

通过根据我所知道的而不是使用在线指南从头开始构建整个电子邮件来解决这个问题: http://jsfiddle.net/hirenshah/k7wg3yry/4/

<body bgcolor="#C0C0C0">
<table class="container">
    <tr>
        <td>
            <!-- Header Table Start -->
            <table dir="rtl" width="100%">
                <tr>
                    <td width="35%" dir="ltr" class="table">RIGHT HAND SIDE LOGO</td>
                    <td width="65%" dir="ltr" class="table">Quote Number: 1234567890</td>
                </tr>
            </table>
            <!-- Header Table End -->
            <!-- Image Banner Table Start -->
            <table class="center">
                <tr>
                    <td>
                        <img src="http://effervescence.me/wp-content/uploads/2014/01/UnencumberedSharingCircleBanner600px.jpg" class="resize" />
                    </td>
                </tr>
            </table>
            <!-- Image Banner Table End -->
            <!-- Intro Text Start -->
            <table>
                <tr>
                    <td>Dear Mr Smith,
                        <br>We are a recognized leader in enterprise engagement and customer experience management and today are proud to count some of the world's largest brands as our customers.
                        <br>
                        <br>The inspiration for our company name is the Thunderhead cloud - a type of storm cloud that signals disruption and turbulence. It's symbolic of the change we bring to enterprise software; a cloud based solution provider leading from the front to revolutionize customer engagement and design-led ease of use.
                        <br>
                        <br>Since launching in 2004, we have become an acknowledged leader in our market, with operations in three continents, and a client base that includes some of the best known companies in the financial services and investment banking world.
                        <br>
                        <br>We help our customers succeed by providing them with innovative technology solutions that enable them to more effectively communicate, collaborate and engage with their customers, employees and partners.
                            </td>
                </tr>
            </table>
            <!-- Intro Text End -->
            <!-- Header Table Start -->
            <table width="100%">
                <tr>
                    <td width="50%" class="table">
                        <p>You have bought stuff</p>
                    </td>
                    <td width="50%" class="table">
                        <p>But you can also buy this stuff</p>
                    </td>
                </tr>
            </table>
            <!-- Header Table End -->
        </td>
    </tr>
</table>

    /* Mobile Devices */
 @media only screen and (max-width: 599px) {
    .table {
        display:block;
        width:100%;
    }
    .container {
        width:300px;
        !important max-width:300px;
        !important
    }
    img.resize {
        max-width:300px;
        height:auto;
    }
}
/* All Other Devices */
 .container {
    background-color: white;
    margin-left: auto;
    margin-right: auto;
    max-width:600px;
    padding:10px;
    border-radius: 20px 20px 20px 0px;
}
.center {
    margin-left: auto;
    margin-right: auto;
}
.left {
    text-align: left;
}
.right {
    text-align: right;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 2011-10-02
    • 2014-11-01
    • 2022-01-14
    • 1970-01-01
    相关资源
    最近更新 更多