html - 居中无间隙的图像和文本
问题描述
我有 2 个带有图像和文本的块。我需要将它们垂直和水平居中。我使用 flexbox,但是当文本较长时 - 图像和文本之间会出现填充。如何删除此填充1
.product-teaser {
width: 235px;
height: 340px;
margin: 10px;
}
img {
margin-right: 5px;
}
.product-teaser-stock {
font-size: 10px;
font-family: "Open Sans";
font-weight: 700;
text-align: center;
text-transform: uppercase;
display: flex;
justify-content: center;
align-items: center;
max-height: 17px;
}
<!DOCTYPE html>
<html>
<head>
<title>Another simple example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="product-teaser">
<div class="product-teaser-stock product-teaser-stock-undefined date-available" style="color:#009900;">
<img class="free-shipping-icon" width="30" src="https://shop.dev.pictureserver.net/images/pic/70/3c/undef_src_shop_shop_id_1_type_shipping_image.png" alt="" title="">
<span class="stock_title">FREE shipping, available from 03.02.2021</span>
</div>
<div class="product-teaser">
<div class="product-teaser-stock product-teaser-stock-undefined date-available" style="color:#009900;">
<img class="free-shipping-icon" width="30" src="https://shop.dev.pictureserver.net/images/pic/70/3c/undef_src_shop_shop_id_1_type_shipping_image.png" alt="" title="">
<span class="stock_title">FREE shipping</span>
</div>
</div>
</body>
</html>
解决方案
如果我理解你的问题,你想让 product-teaser 的第一个 div 中的文本.product-teaser
。
我建议您使用带有 stock_title 类的块.stock_title
来将文本向左对齐,以避免图像和左侧之间的间隙。
我想这段代码会有所帮助
.stock_title {
text-align: left;
}
推荐阅读
- r - 使用 broom::tidy 为 GAM 系数和置信区间取幂
- excel - SAP Webi 文档转 Excel,其他值没有小数位
- discord.py - 如何从错误函数中重置命令冷却时间
- javascript - 在 Javascript 中,我的文本字段无法识别名称中的特殊符号(é 字符)
- arrays - 将数组的内容打印为字符串
- powershell - 为什么通过 Dropbox API 查看的两个文件具有相同的 id?
- macos - macOS:确定从 iconForFile 方法返回的图标的实际大小
- excel - 使用 userfom 时间间隔数据绘制图表时遇到问题
- javascript - 如何为php制作的表生成id
- php - 在选择文本选项中突出显示特定文本的颜色