简体   繁体   English

如何仅使用嵌入式样式删除跨度元素之间的空间?

[英]How to remove space between span elements using inline style only?

I would like to display a single word "WorldWide" in two colors(red and blue). 我想用两种颜色(红色和蓝色)显示一个单词“ WorldWide”。

I've tried using span elements as below. 我已经尝试过使用span元素,如下所示。

<span style="color:red">World</span><span style="color:blue">Wide</span>

but the issue is that the email clients format the html as below so the text ends-up displayed in two words (World Wide instead of WordWide) due the new lines added in the html. 但是问题是电子邮件客户端按如下所示格式化html,因此由于html中添加了新行,因此文本最终以两个单词(World Wide而不是WordWide)显示。

<span style="color:red">World
</span>
<span style="color:blue">Wide
</span>

So my question is: How can I display a single word in two colors considering that the html clients format/add new lines to span elements? 所以我的问题是:考虑到html客户端格式化/添加新行以跨越元素,我如何以两种颜色显示单个单词? Please note that only inline styling is allowed in email clients so I can't use <style></style> tags. 请注意,电子邮件客户端仅允许使用内联样式,因此我不能使用<style></style>标签。

You can float the first element. 您可以float第一个元素。

 <span style="color:red; float: left;">World</span> <span style="color:blue">Wide</span> 

The float property specifies whether or not a box (an element) should float. float属性指定框(元素)是否应该浮动。 You may add the float in your span tag. 您可以在您的span标签中添加float For your code you just need, float:left with the first span tag. 对于您的代码,只需要使用float:left和第一个span标签即可。

So it will be 这样就可以了

 <span style="color:#FF0000; float: left">World</span> <span style="color:#0D0DFF;">Wide</span> 

I know float doesnt work that well with emails. 我知道float不能很好地处理电子邮件。 I know spans are inline blocks but adding the code for inline might make it work. 我知道span是内联块,但是为内联添加代码可能会使它工作。

 <span style="color:red;display:inline-block;">World</span> <span style="color:blue;display:inline-block;">Wide</span> and the rest of the words 

Let me know if this works. 让我知道这个是否奏效。

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

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