html - 当我想在中心对齐内容时,Justify-self 不起作用
问题描述
我必须使用自动边距来对齐页面中心的内容。
div {
background: #121212;
font-size: 100%;
display: flex;
}
a {
color: #fff;
padding: 2%;
display: inline-block;
background: linear-gradient(180deg, rgba(18, 18, 18, 0.8) 0%, rgba(18, 18, 18, 0.5) 66.66%), url('https://cml.sad.ukrd.com/image/714544.png');
background-size: cover;
background-position: top;
white-space: nowrap;
font-size: 18px;
}
img {
height: 100%;
width: auto;
display: flex;
align-self: center;
max-height: 50px;
margin: 0 auto;
/* fails justify-self: center; */
}
<div>
<a href="#">⟵ Some Text Goes Here</a>
<img src="https://cml.sad.ukrd.com/image/714824.png">
</div>
我想了解如何将块图像放置在父 div 的中心。div 已经有另一个<a>
孩子,它正在将块图像稍微推出中心。div 父级是一个 flexbox,我认为有一个justify-self: center
规则会起作用,但显然不是,因此我必须使用margin: 0 auto
,它无论如何都不能完全居中对齐。
块图像如何位于父 div 的死点?
解决方案
justify-self: center;
是 css 的属性grid
,而不是flex
. https://css-tricks.com/snippets/css/complete-guide-grid/#prop-justify-self
推荐阅读
- linux - cAdvisor 不显示所有容器的正常运行时间(Prometheus+cAdvisor+Grafana)
- c# - 尝试为android运行stockfish二进制文件时出现system.componentmodel.win32异常
- c# - c# sql 随时随地通过 odbc 文本格式化变音符号 (öäü)
- ios - IOS如何彻底删除一个View
- laravel - laravel中如何使用collection合并数组,使一个成为key?
- mysql - Laravel 按日期排序,空日期总是在最后
- vue.js - 被称为“更新”钩子的被破坏组件
- go - 如何在 Reflect.FieldByName() 中读取切片
- vbscript - 如果超过 50,QTP 无法在下拉列表中选择数据
- r - 在设备中绘制图形