在下一个js中定位图像

Rob*_*gar 5 css reactjs next.js

我想将我的图像放在页面的最右侧,我尝试使用 和 进行position: absolute修改right: 0。我还尝试将父位置设置为相对位置,将图像位置设置为绝对位置,但为什么它不起作用?

这是我的 jsx 文件

        <div className={styles.images}>
          <Image
            src="/cloud.svg"
            alt="Picture of the author"
            layout="fill"
            className={styles.cloud}
          />
          <Image
            src="/kuil.svg"
            alt="Picture of the author"
            height={200}
            width={600}
            layout="intrinsic"
            className={styles.building}
          />
        </div>
Run Code Online (Sandbox Code Playgroud)

也在我的 css 文件中。

.images {
    position: relative;
    margin: 90px auto 0 auto;
}

.building {
    position: absolute;
    top: 0;
    right: 0 !important;
    bottom: 0 !important;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Him*_*til 12

我也遇到过同样的问题。编译时,Image 标签用相对样式位置的 div 标签包裹 img 标签。

解决方案是简单地将 Image 标签用 div 包裹起来,并将类名添加到 div 中。

检查代码沙箱

  • 我到处都看到这个解决方案,但它对我来说根本不起作用:( 我可以绝对定位 PNG/SVG 图像的唯一方法是使用 &lt;img&gt; ,它显示警告并说我不能使用它(我假设它们不是针对我正在使用的静态 HTML 导出/NextJS 期间进行了优化)。我真的需要能够将图像移动到屏幕上任何我想要的位置,但我不知道如何在这个有限且相当烦人的 &lt;Image/&gt; 内做到这一点NextJS 中的组件...它带走了我需要/学会使用的很多功能 (4认同)