【问题标题】:Table: Extra text in new line表:新行中的额外文本
【发布时间】:2016-09-15 18:17:32
【问题描述】:

我有一张图片。

现在,我的疑问是,我希望图像下方的文本换行如果文本太长。当我输入长文本时,单元格(td)会被放大,这是我不想放大的。

所以我希望额外的文本在新行中。它应该限制为图像的宽度,之后额外的文本应该在新行中。

我不能使用 divposition 属性。我只能使用 table 标签。

图像高度应该相同。我曾尝试使用 word-wrapwhite-space,但图像高度会因此而有所不同。

<table bgcolor="black" style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt; border: thin white solid; " align="left" border="0" cellpadding="0" cellspacing="0"  >
                                                <tbody>

                                                <td align="center">
                                                    <table  style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;" align="center" border="0" cellpadding="0" cellspacing="0" width="120">
                                                        <tbody><tr>
                                                            <td align="center" height="100" valign="top" width="100">
                                                                <p style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;"><a class="modimg" style="text-decoration: none!important;" href="#"><img style=" border: 3px solid #ffcbbc ; outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;" alt="" src="http://www.hubilo.com/eventApp/ws//images/speaker/profile/thumb/2712_1455301580.jpeg" border="0" height="110" width="110" ></a></p>
                                                            </td>
                                                        </tr>
                                                        </tbody></table>
                                                </td>


                                                <tr>
                                                    <td class="h2" style=" font-weight: bold ;font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 10px;padding-top: 2px;padding-bottom: 0px;color:#ffffff;">
                                                       <p style="padding:0; margin:0;text-align: center;"> <span class="wrap_textbox">dsdsfsdfsdsfsdsdgsgdsdfsdfd</span></p>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="h2" style="font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 8px;text-align: center;color: #ffffff;">
                                                        <span class="wrap_textbox">Co-Founder at SeeFund</span>
                                                    </td>
                                                </tr>

                                                </tbody>

                                            </table>


                                            <!--Speaker 2-->

                                            <table  style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt; margin: 0 auto; margin-left: 15px;  " align="left" border="0" cellpadding="0" cellspacing="0" >
                                                <tbody>
                                                <tr>
                                                    <td align="center">
                                                        <table style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;" align="center" border="0" cellpadding="0" cellspacing="0" width="120">
                                                            <tbody><tr>
                                                                <td align="center" height="100" valign="top" width="100">
                                                                    <p style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;"><a class="modimg" style="text-decoration: none!important;" href="#"><img style=" border: 3px solid #ffcbbc ; outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;" alt="" src="http://www.hubilo.com/eventApp/ws//images/speaker/profile/thumb/2712_1455949782.jpeg" border="0" height="110" width="110" ></a></p>
                                                                </td>
                                                            </tr>
                                                            </tbody></table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="h2" style=" font-weight: bold ;font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 10px;padding-top: 5px;padding-bottom: 0px;text-align: center;color:#ffffff; ">
                                                        <span class="wrap_textbox">Mr. R Chandrasekhar</span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="h2" style="font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 8px;text-align: center;color: #ffffff;">
                                                        <span class="wrap_textbox">President of NASSCOM</span>
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>



                                            <!--Speaker 3 -->

                                            <table  style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt; margin: 0 auto;  margin-left: 15px;  " align="left" border="0" cellpadding="0" cellspacing="0" >
                                                <tbody>
                                                <tr>
                                                    <td align="center">
                                                        <table style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;" align="center" border="0" cellpadding="0" cellspacing="0" width="120">
                                                            <tbody><tr>
                                                                <td align="center" height="100" valign="top" width="100">
                                                                    <p style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;"><a class="modimg" style="text-decoration: none!important;" href="#"><img style=" border: 3px solid #ffcbbc ; outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;" alt="" src="http://www.hubilo.com/eventApp/ws//images/speaker/profile/thumb/2712_1455627060.jpeg" border="0" height="110" width="110" ></a></p>
                                                                </td>
                                                            </tr>
                                                            </tbody></table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="h2" style=" font-weight: bold ;font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 10px;padding-top: 5px;padding-bottom: 0px;text-align: center;color:#ffffff;">
                                                        <span class="wrap_textbox">Mr. Jay Panda</span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="h2" style="font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 8px;text-align: center;color: #ffffff;">
                                                        <span class="wrap_textbox">Member of Parliament</span>
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>


                                            <!--Speaker 4 -->


                                            <table  style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt; margin: 0 auto;  margin-left: 15px;  " align="left" border="0" cellpadding="0" cellspacing="0" >
                                                <tbody>
                                                <tr>
                                                    <td align="center">
                                                        <table style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;" align="center" border="0" cellpadding="0" cellspacing="0" width="120">
                                                            <tbody><tr>
                                                                <td align="center" height="100" valign="top" width="100">
                                                                    <p style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;"><a class="modimg" style="text-decoration: none!important;" href="#"><img style="border: 3px solid #ffcbbc; outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;" alt="" src="http://www.hubilo.com/eventApp/ws//images/speaker/profile/thumb/2712_1455300140.jpeg" border="0" height="110" width="110" ></a></p>
                                                                </td>
                                                            </tr>
                                                            </tbody></table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="h2" style=" font-weight: bold ;font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 10px;padding-top: 5px;padding-bottom: 0px;text-align: center;color:#ffffff;">
                                                        <span class="wrap_textbox">Ms. Shazia Ilmi</span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="h2" style="font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 8px;text-align: center;color: #ffffff;">
                                                        <span class="wrap_textbox">Spokesperson at BJP</span>
                                                    </td>
                                               </tr>
                                    </table>

【问题讨论】:

  • 天哪,你已经使用了很多表格来进行简单的布局:|为什么必须使用表格?
  • 我希望每个 td 在不同的表中。这就是为什么。或者有什么简单的方法吗?
  • 您可以将类添加到&lt;td&gt;,例如&lt;td class="firstTable"&gt;。不过,我已经为您添加了解决方案。

标签: html css html-table


【解决方案1】:

所以这就是我所做的......

<table bgcolor="black" style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt; border: thin white solid; " align="left" border="0" cellpadding="0" cellspacing="0"  >
    <tbody>

    <td align="center">
        <table  style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;" align="center" border="0" cellpadding="0" cellspacing="0" width="120">
            <tbody><tr>
                <td align="center" height="100" valign="top" width="100">
                    <p style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;"><a class="modimg" style="text-decoration: none!important;" href="#"><img style=" border: 3px solid #ffcbbc ; outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;" alt="" src="http://www.hubilo.com/eventApp/ws//images/speaker/profile/thumb/2712_1455301580.jpeg" border="0" height="110" width="110" ></a></p>
                </td>
            </tr>
            </tbody></table>
    </td>


    <tr>
        <td class="h2" style=" font-weight: bold ;font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 10px;padding-top: 2px;padding-bottom: 0px;color:#ffffff;">
            <p style="padding:0; margin:0;text-align: center; max-width:116px;"> <span class="wrap_textbox">Lorem ipsum dolor sit amet, consectetur adipisicing elit. A consequuntur corporis, debitis dignissimos error fuga id inventore laudantium officiis quae quam, quia quos, repudiandae saepe sed sint tenetur? Doloribus, recusandae?</span></p>
        </td>
    </tr>
    <tr>
        <td class="h2" style="font-family: 'proxima_nova_rgregular', Arial, helvetica, sans-serif;font-size: 8px;text-align: center;color: #ffffff;">
            <span class="wrap_textbox">Co-Founder at SeeFund</span>
        </td>
    </tr>

    </tbody>

</table>

只需添加:max-width:116px;(或任何您喜欢的最大宽度),然后它会自动为您移动到新行。

更新

这是我添加样式的行:

       <p style="padding:0; margin:0;text-align: center; max-width:116px;">

我强烈建议将它们放入 CSS 类中,然后放入样式表中,因为如果您以后希望调整代码,则必须进入每个文件并调整每个标签下的 style="" 标签已添加到。

【讨论】:

  • 谢谢。它按我的预期工作。你拯救了我的一天.. 非常感谢.. :)
  • 完全没问题。作为一个指针,请查看您的代码并查看我提到的样式表以及 1 个表格而不是众多表格。如果您决定以响应式网站为例,您将来会遇到问题。
  • 我总是在单独的样式表中编写 CSS 并提供参考。但我正在制作 HTML 电子邮件。所以像 Outlook 这样的电子邮件引擎不采用外部样式表。这就是为什么我必须使用 table 标签并坚持使用内联 CSS .. :(
  • 啊,我明白了。那就不是问题了。我的假设是它是针对一个网站的,因为您最初并没有透露它是针对电子邮件的。 :) 祝你好运!
  • 请为此道歉。但是我总是在开发时尽量避免使用内联 CSS。但在这种情况下,我必须使用它。再次,谢谢你.. :)
猜你喜欢
  • 1970-01-01
  • 2012-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-27
  • 2015-06-12
  • 1970-01-01
相关资源
最近更新 更多