简体   繁体   English

如何根据屏幕尺寸更改表格?

[英]How to change my table based on screen size?

I want to change my table so it would look nice on a mobile platform. 我想更改表格,使其在移动平台上看起来不错。 All I want to do is change my table so it is two columns. 我要做的就是更改表,使其为两列。 I am using this code to send an email. 我正在使用此代码发送电子邮件。 So I cannot link a stylesheet to my html. 所以我不能将样式表链接到我的html。 It is recommended that I use inline styles. 建议使用内联样式。 Is it possible to accomplish this using javascript? 是否可以使用javascript完成此操作?

Here is what I tried: 这是我尝试过的:

<script>
    $(document).ready(function() {
    if ($(window).width() < 1024) {
        <table align="center">
            <tr>
                <td style="vertical-align: top;">Property:</td>
                <td style="padding-left: 10px; font-weight: bold; width: 300px;">115 EAST 9TH STREET<br>NEW YORK, NY, 10003</td>
            </tr>
            <tr>
                <td style="vertical-align: top;">Resident Name:</td>
                <td style="padding-left: 10px; font-weight: bold; width: 300px; vertical-align: top;">MAILBOXES ETC.</td>
            </tr>
            <tr>
                <td style="">Unit:</td>
                <td style="padding-left: 10px; font-weight: bold;">STORE</td>
            </tr>
            <tr>
                <td style="">Account #:</td>
                <td style="padding-left: 10px; font-weight: bold;">xxx-xxx</td>
            </tr>
        </table>
    } else {
        <table align="center">
            <tr>
                <td style="vertical-align: top;">Resident Name:</td>
                <td style="padding-left: 10px; font-weight: bold; width: 300px; vertical-align: top;">MAILBOXES ETC.</td>
                <td style="vertical-align: top;">Property:</td>
                <td style="padding-left: 10px; font-weight: bold; width: 300px;">115 EAST 9TH STREET<br>NEW YORK, NY, 10003</td>
             </tr>
             <tr>
                  <td style="">Unit:</td>
                  <td style="padding-left: 10px; font-weight: bold;">STORE</td>
             </tr>
             <tr>
                 <td style="">Account #:</td>
                 <td style="padding-left: 10px; font-weight: bold;">xxx-xxx</td>
             </tr>
         </table>
       }});
 </script>

Any help will be greatly appreciated. 任何帮助将不胜感激。

No, definitely don't use Javascript for email sending, as most clients fully disable it. 不,绝对不要使用Javascript发送电子邮件,因为大多数客户端会完全禁用Javascript。

You wouldn't need Javascript at all even if you were designing your table for web browsers only. 即使只为Web浏览器设计表,也根本不需要Javascript。 All your problems can be solved with well applied media queries , if you wanna spend a little time doing further readings on that topic. 如果您想花一点时间做有关该主题的进一步阅读,那么可以通过应用很好的媒体查询来解决所有问题。 No doubt it's worth it. 毫无疑问,这是值得的。

For emails, I recommend reading this awesome article about using media queries for emails . 对于电子邮件,我建议阅读这篇很棒的文章,有关使用媒体查询电子邮件 One huge downside of this is the lack of support by Gmail (which the author states in the end of the text). 其中一个巨大的缺点是Gmail缺乏支持(作者在本文末尾指出)。 If covering Gmail users is a must, you'll have to stick with the most basic responsive practices as long as I'm aware, such as using em and/or % units for width , height , padding , margin etc instead of px in your CSS styles. 如果必须覆盖Gmail用户,只要我知道,您就必须坚持最基本的响应做法,例如将em和/或%单位用于widthheightpaddingmargin而不是px in您的CSS样式。

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

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