简体   繁体   English

如何使我的图像在响应时保持其方形形状并且不设置大量媒体查询?

[英]How can I make my image maintain its squared shape when responsive and not set lots of media queries?

I've read several answers regarding the same question I have, but none seem to work for me.我已经阅读了关于我遇到的同一个问题的几个答案,但似乎没有一个对我有用。 I have a form where users will be able to edit or add images.我有一个表单,用户可以在其中编辑或添加图像。 I want each image to be a square, regardless of the device (desktop, mobile, tablet).无论设备(台式机、移动设备、平板电脑)如何,我都希望每个图像都是正方形。 I'm not achieving this.我没有做到这一点。 In other answers people have recommended using width: 20vw and height: 20vh , in other posts it's been mentioned to use :after , but none are working for me.在其他答案中,人们建议使用width: 20vwheight: 20vh ,在其他帖子中提到使用:after ,但没有一个对我有用。 I was hoping to achieve this without having to create media queries for each screen.我希望在不必为每个屏幕创建媒体查询的情况下实现这一点。

This is what I need to achieve:这是我需要实现的:

这是我需要实现的

Here's my codepen .这是我的代码笔

From what I understand IF you want square images据我了解,如果您想要方形图像

You can make the width and height always same number您可以使宽度和高度始终相同

But If you always want it to same square size但是如果你总是希望它是相同的正方形大小

you can use something like this你可以使用这样的东西

.square{
  width: 100px;
  height: 100px
}

OR或者

.square{ width: 20vw; height: 20vw; }

.square{   width: 20vh;   height: 20vh; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM