我不得不使用自动边距来对齐页面中心的内容。
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; */
}Run Code Online (Sandbox Code Playgroud)
<div>
<a href="#">? Some Text Goes Here</a>
<img src="https://cml.sad.ukrd.com/image/714824.png">
</div>Run Code Online (Sandbox Code Playgroud)
我想发现如何将块图像定位在父 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
| 归档时间: |
|
| 查看次数: |
4175 次 |
| 最近记录: |