【发布时间】:2017-03-20 18:54:10
【问题描述】:
我正在尝试将由锚标记包裹在 div 内的图像居中。我尝试使用 display flexbox 和 justify-content:center 在一定程度上工作的图像,但是图像的高度保持不变,而宽度相应地改变,所以当我从桌面缩小到移动时,压缩了图像......从而失去了它的质量。
我怎样才能使这张图片居中。
注意:我使用的是纯波本威士忌
这就是我所拥有的
HTML
<div class="project">
<a class="project__thumb" href="{{ project.url }}" target="_blank">
<img src="{{ site.baseurl }}img/{{ project.thumbnail }}">
</a>
</div>
SCSS
.project{
width: 80%;
margin: 0 auto; /*center whole block for mobile*/
height: auto;
margin-bottom: 60px;
border-radius: 2px;
position: relative;
a{
display: flex;
justify-content: center;
}
img{
max-width: 100%; /*make image responsive*/
height: auto; /*make image responsive*/
border-radius: 2px;
transition: opacity 0.25s ease-in-out;
}
}
@include media ($tablet){
.main__projects{
@include span-columns(12);
}
.project{
@include span-columns(6 of 12);
@include omega(2n);
margin-bottom: 50px;
}
}
@include media ($desktop){
.main__projects{
@include span-columns(12);
}
.project{
@include span-columns(4 of 12);
@include omega(3n);
margin-bottom: 100px;
}
}
【问题讨论】:
-
代码似乎工作正常,有什么问题?
-
图像的高度保持不变,而宽度相应地改变。导致图像变得压缩和压扁......即使我已经让它响应了。