[英]How do I make CSS/HTML margins responsive based on screen size in Angular/Ionic
There are two ways, I think, to go about my issue but this is just one of them.我认为有两种方法可以解决我的问题,但这只是其中一种。 I have this code:
我有这个代码:
<ion-row style="height: 28%" class="first_row">
<ion-col size="12" style="height: 100%" class="ion-text-center">
<div>
<img src="assets/img/picture.png" class="picture"/>
</div>
</ion-col>
</ion-row>
CSS: CSS:
.picture { object-fit: fill; width: 45%; border-radius: 5px; margin-top: 10%; }
What this code does is set a row height of 28%, that I fill with a color.这段代码的作用是将行高设置为 28%,我用颜色填充。 I then have a picture on top of the row with a margin that I set from the top of the screen.
然后我在行的顶部有一张图片,我从屏幕顶部设置了一个边距。 So it looks something like this:
所以它看起来像这样:
My Dilema is that it looks great on an iphone6/7/8 Screen, but when I go to Iphone X screen, it looks like this:我的困境是它在 iphone6/7/8 屏幕上看起来很棒,但是当我转到 Iphone X 屏幕时,它看起来像这样:
I know there has to be a better way to be responsive, but I'm not entirely sure how.我知道必须有更好的方式来响应,但我不完全确定如何。 Because I want the code to look exactly how it looks on a smaller device, on a bigger device.
因为我希望代码在较小的设备上和较大的设备上看起来完全一样。 That's why I don't know if I need to change the margins based on screen size (which I don't know how), or change the row height based on screen size.
这就是为什么我不知道是否需要根据屏幕大小(我不知道如何更改)更改边距,或根据屏幕大小更改行高。 If you might know, please feel free to help.
如果您知道,请随时提供帮助。
您可以为此使用 css 媒体查询或类似 bootstrap 的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.