2 回答
TA贡献1744条经验 获得超4个赞
首先注意:纵向图像永远不会填充与水平图像相同的空间,而不会倾斜图像的纵横比,这就是您在代码/示例中看到的。
假设所需的效果是让它们显示为“相同大小”,您最终会得到一个正方形的图像项目。在你的例子中.max-image-set
如果您使用相同的最大高度设置纵向和横向样式,则纵向图像的左侧和右侧将有空白。横向地,如果您使用相同的最大宽度设置它们的样式,您将在横向图像的上方和下方有空白。(假设它们在一个正方形中,并且期望的效果是让它们看起来“相同大小”)
.main-image-set a {
display: flex; /* for alignment */
justify-content: center; /* horizontally align portrait image */
align-items: center; /* vertically align landscape image */
/** fixed width, creates a square for our image to live */
width: 414px;
height: 414px;
/* Could be styles with a responsive technique a like aspect ratio prop, but that is outside the scope of here */
background-color: #eee; /* so you can see the "square", for demo purposes */
}
.main-image-set img {
width: auto; /* to counter any width attributes and allow intrinsic image width */
height: auto; /* to counter any height attributes and allow intrinsic height */
max-width: 100%; /* scale with the parent element width */
max-height: 100%; /* scale with the parent element height */
}
这将导致这样的事情......

TA贡献1831条经验 获得超9个赞
亲爱的@dylanjameswagner 我想怎么做
如果您使用相同的最大高度设置纵向和横向样式,则纵向图像的左侧和右侧将有空白。
我尝试了很多次,但我不能,我希望它像这样告诉我

在图像外观上,我想在框架的中心显示纵向图像,左右两侧都有一个空白区域,但如果图像是横向的,它会显示在整个框架内部,而不是显示两侧的空白区域。
添加回答
举报
