Ago*_*gos 13 html css css-position hotmail css-float
我试图看看是否可以在图像上放置一些文本而不使用position:absolute或者将图像作为元素的背景.
限制的原因是HTML代码进入电子邮件,事实证明hotmail既不支持也不支持.
我记得当我第一次开始学习CSS时,摆弄图像周围的浮动文本时,我常常最后快速地将图像传遍整个图像.可悲的是,我不能重现那种行为.
全文(编辑):
我从图形设计师那里得到了一个精美的布局.它基本上是一个很好的背景图片,标识链接到网站,基本上是中间的"文本到达"区域.
像往常一样,在这些情况下,我正在使用表来确保所有内容都保持原位并运行crossbrowser + crossmailclient.
问题来自于中间的"文本到此处"区域不是白色矩形,而是具有一些背景图形.
经过一些测试,看起来Live Hotmail似乎不喜欢这两个位置:绝对或背景图像; 相对利润也不好,因为它们会破坏其余的布局.
当前版本,适用于任何其他邮件客户端/网站:
...
<td>
<img src='myimage.jpg' width='600' height='400' alt=''>
<p style="position: absolute; top: 120px; width: 500px; padding-left: 30px;">
blablabla<br>
yadda yadda<br>
</p>
</td>
...
Run Code Online (Sandbox Code Playgroud)
当然,"这是不可能的"可能是一个完全可以接受的答案,但我希望不是;)
Zan*_*ano 67
一旦桌子出现,我曾经一直拉这样的特技.非常丑陋,并且可能会严重篡改您运行它的任何验证器:重叠表格单元格.适用于大多数浏览器,甚至没有CSS.
例:
<table>
<tr>
<td></td>
<td rowspan=2><img src="//i.stack.imgur.com/XlOi4.png"></td>
</tr>
<tr>
<td colspan=2>This is the overlay text</td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
我知道,我应该为此付出代价.
如果使用绝对定位,则应指定left和top属性.此外,您应该position:relative;在某个父元素上设置它以使其成为图层,以便绝对定位将该元素用作原点.如果您没有指定原点,它可能是窗口,也可能是其他元素,并且您不知道绝对定位元素的最终位置.
还有一些其他替代方案可以将元素放在彼此的顶部,每个元素都有自己的局限性.
您可以使用相对定位在文档顶部显示文本:
<img src="..." alt="" />
<div style="position:relative;top:-50px;">
This text will display 50 pixels higher than it's original position,
placing it on top of the image. However, the text will still take up
room in it's original position, leaving an empty space below the image.
</div>
Run Code Online (Sandbox Code Playgroud)
您可以在另一个元素中使用浮动元素将文本放在图像的顶部:
<div>
<div style="float:left;">
This text will be on top of the image. The parent element
gets no height, as it only contains floating elements.
However, IE7 and earlier has a bug that gives the parent
element a height anyway.
</div>
</div>
<img src="..." alt="" />
Run Code Online (Sandbox Code Playgroud)