【问题标题】:Center text in a css border-triangle in email在电子邮件中的 css 边框三角形中居中文本
【发布时间】:2019-07-07 15:17:06
【问题描述】:

我正在尝试在电子邮件中使用 css 边框生成一个三角形,并在其中放入一些动态文本(数字),但我想将其设置为三角形中心,但我无法使用定位,因为它已从内联css

我尝试将三角形 css 的 div 和文本跨度放在 div 容器中并使用位置对齐 - 没有用

<div style="<%= MailComponents.create_style('display' => 'inline-block', 'width' => '2px', 'height' => '0px', 'border-radius' => '4px' ,'border-left' => '20px solid transparent', 'border-right' => '20px solid transparent' ,'border-bottom => '30px solid #FC577A', 'color' => '#fff', 'vertical-align' => 'middle', 'line-height' => '28px', 'margin-top' => '-10px') %>">
            <span style="<%= MailComponents.create_style('position' => 'relative', 'left' => '-8px','vertical-align' => 'middle', ) %>">
              <%= some dynamically generated number %>
            </span>
          </div>

试过这个技巧

http://jsfiddle.net/VScFS/57/

没有帮助 我想知道这是否可以用表格来完成

【问题讨论】:

    标签: css email border css-shapes text-alignment


    【解决方案1】:

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    .container {
      display: grid;
      grid-template-columns: auto;
      justify-content: center;
      align-items: center; 
    }
    
    .wrapper {
      background: #000;
      width: 200px;
      height: 200px;
      -webkit-clip-path: polygon(0% 87%, 50% 0%, 50% 0%, 100% 87%);
      clip-path: polygon(0% 87%, 50% 0%, 50% 0%, 100% 87%);
    }
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width">
      <title>JS Bin</title>
    </head>
    <body>
    <div class="container">
      <div class="wrapper">
      </div>
    </div>
    </body>
    </html>

    在父类上使用 display:gridjustify-content: center; 使其水平居中对齐!作为参考,您可以查看https://www.w3schools.com/cssref/pr_grid.asp此链接。希望对你有帮助

    【讨论】:

    • Tnx!我不知道电子邮件中支持网格,这在将来可能对其他事情也很有帮助。
    • @AQUANGEL 网格可以删除并替换为其他内容,但我怀疑电子邮件中是否支持剪辑路径。我很确定它会失败
    • 如果您正在使用电子邮件模板,我建议您使用三角形图像并在 td 上使用 align="center",因为剪辑路径不适用于 Outlook 客户端。
    • 所以 justify 内容中心似乎在 gmail 中不起作用:\ 三角形图片的想法听起来不错,唯一的问题是我们烦人的设计师会像 - 不!创建三角形是你的工作!你来弄吧!嗯
    • 你可以在谷歌上找到大量的图片。检查此解决方案jsbin.com/halosedixi/2/edit?html,output
    猜你喜欢
    • 1970-01-01
    • 2012-11-26
    • 2020-06-22
    • 1970-01-01
    • 2017-01-14
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多