简体   繁体   English

调整大小时保持图像对齐

[英]Keep image aligned in form when resizing

I have this image (the curve): 我有这张图片(曲线):

在此处输入图片说明

It shows part of the next section because the image form is narrower on the part and the width is over 1000px aprox. 它显示了下一部分的内容,因为该部分的图像形式较窄并且宽度超过1000像素左右。

My CSS for it is: 我的CSS是:

.img{
    width: 100%;
    height: auto;
}

It should always look like this: 它应始终如下所示:

在此处输入图片说明

How could I make that happen independently of viewport width? 我如何独立于视口宽度来实现这一点?

The css property "background-position" can be very helpful with centering/placing an image in a certain position so it sizes better across responsive screens. css属性“背景位置”在将图像居中/放置在特定位置时非常有用,因此在响应屏幕上尺寸更好。

Have you tried displaying the image as a background image of a custom div which would have the properties you listed above, in a way similar to something like this: 您是否尝试过以类似于以下方式将图像显示为自定义div的背景图像,该图像具有上面列出的属性:

.image-div {
    width: 100%;
    height: auto;
    background-image: url('my-image.jpg');
    background-position: center top;
}

Or something to that equivalent? 或类似的东西? I can't say exactly how to set background-position with your image as I'm unsure of its dimensions and where that curve lies in the image. 我不确定要如何设置图像的背景位置,因为我不确定其尺寸以及该曲线在图像中的位置。

There some good info about the background-position property here. 这里有一些有关background-position属性的好信息。

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

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