css - 在它的容器中居中图像
问题描述
我似乎无法将我的图像居中,它相对于它的父级是绝对定位的,它是相对的。
我用检查元素尝试了很多方法,但它似乎不想工作。
请在此处查看示例:http: //dassiedev.dassieartisan.com/furniture
这是我的CSS:
.tm-switch-image-container {
position: relative;
overflow: hidden;
height: 276px;
}
.tm-switch-image-container img {
width: 276px;
height: 276px;
max-width: none;
}
解决方案
要img
在 a中居中div
,给出img
adisplay: inline-block
规则,然后给出div
atext-align: center
规则。这将使其水平居中。
.tm-switch-image-container {
position: relative;
overflow: hidden;
height: 276px;
text-align: center;
}
.tm-switch-image-container img {
width: 276px;
height: 276px;
display: inline-block;
}
推荐阅读
- sql - THING 的每日活动计数来自详细说明 THING 变化的行
- scala - 字符串scala中的ReplaceAll正则表达式模式
- c++ - 将编译时 C 回调转换为编译时 C++ 回调
- oop - 是否有与 Java 接口(“类...实现”)等效的 Delphi?
- c# - DllImport 不适用于 docker windows 容器
- google-chrome - 自签名 SSL 证书(添加到 Keychain 并标记为 Trusted)在 Chrome 中显示无效
- swagger - 引用定义但从中减去“id”属性?
- dart - 飞镖中的两个点 (..)
- sql - 我们如何在 .bat 脚本中使用 SQL LIKE 运算符
- compiler-errors - 致命错误 [Pe 1696]:无法打开源文件“intrinsic.h”