css - 在电子邮件中的 css 边框三角形中居中文本
问题描述
我正在尝试在电子邮件中使用 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/
没有帮助我想知道这是否可以用表格来完成
解决方案
* {
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:grid和justify-content: center; 将其水平居中对齐!作为参考,您可以查看https://www.w3schools.com/cssref/pr_grid.asp这个链接。希望它会有所帮助
推荐阅读
- c# - 间歇性依赖注入失败
- angular - 如何代理使用 DI 的组件?
- python - Python 脚本生成 500 内部服务器错误,但不同文件中的代码工作正常
- javascript - 在 gulp 捆绑和 uglify 之后在 IIFE 中未定义上下文
- xamarin.forms - Visual Studio 2019 和 iOS:本机链接失败
- cmake - 如何使用 cmake 定位 jupyter notebook 安装
- swift - 在 MacOS 中模拟媒体键按下
- android - ActionBar 与 TextView 重叠,ConstraintLayout 问题
- javascript - 如何允许同一个 socket.io 房间的人访问同一个 redux 商店?
- matlab - 如何在 Matlab 中同时绘制椭圆和抛物线?