html - 为什么我的图像没有按照我喜欢的方式对齐?
问题描述
我的 CSS 有什么问题?为什么我的图像不居中?
我已经尝试过margin: 0;
,display: block;
但这不起作用。
<style>
.card-header img{
width: 100%;
height: auto;
padding: 20px;
margin: 0 auto; //this one already try
display: block; //also this one
}
.banner-banner {
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-right: 0;
margin-left: -5px;
background: linear-gradient(to bottom, #230343 0%, #A558F1 100%);
}
</style>
解决方案
我假设您正在寻找一张分为 header\body\footer 的卡片(类似这样)
您发送的图像的宽度为 100%,因此它没有任何位置可以将自身与中心对齐。
我建议您在整个卡片标题上使用背景图像,或者将您的图像更改为具有低于其容器的宽度。
如果您更改图像的宽度,这也可以解决问题:
.card-header {
display: flex;
justify-content: center;
}
推荐阅读
- python - 如何监听来自其他设备的 TCP 输入?
- html - 如果我不能使用单选组,如何将 Angular Material 单选按钮与表单控件相关联?
- kubernetes - kubernetes 没有到达内部注册表
- java - Jackson 如何处理映射冲突?
- git - 我将如何在 GIT 中保持本地更改进行 PULL
- java - android 中的 ApiException,状态码为 7,同时使用安全网认证 API
- java - 如何在同一循环中访问哈希图中的 2 个键?
- google-apps-script - 在应用程序脚本中使用标头发出 curl 请求
- python - 如何获取从方法返回的数据并再次在同一方法中使用它?
- javascript - 将 php 代码放入 yii 框架的 registerScript 中