I made a component in React + SCSS. It works as it should on Chrome: enter image description here

But when I open the same page in Firefox, it moves top left and looks weird: enter image description here

我必须做什么更改才能使它在Firefox(和所有其他浏览器)上工作?我想问题出在元素的相对和绝对位置,但我不知props 体在哪里.

.main-country-post-container {
  position: relative;
  cursor: pointer;
}

.main-country-post-bg-image-container {
  width: 100%;
  height: 256px;
  filter: blur(4px);
  box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25);
  border-radius: 12px;

  img {
    object-fit: cover;
    height: 100%;
    width: 100%;
    border-radius: 12px;
  }

  &::before {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(256, 256, 256, 0.85);
    border-radius: 12px;
  }
}

.main-country-top-layer {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
}

.main-country-post-top-image-container {
  height: calc(256px - 108px); /* 72 */
  filter: blur(4px);
  box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25);
  border-radius: 12px;

  img {
    object-fit: cover;
    height: 100%;
    width: 100%;
    border-radius: 12px;
  }
}

.main-country-icon-container {
  position: absolute;
  display: flex;
  justify-content: center;
  width: 100%;
  bottom: 88px; /* 48 */
}

.main-country-icon-circle {
  background: #ffffff;
  border-radius: 50%;
  padding: 4px;
  display: flex;
  justify-content: center;
  align-items: center;

  img {
    width: 36px;
    height: 36px;
  }
}

.main-country-post-text-container {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 104px; /* 72 */
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  font-weight: 800;
  font-size: 20px;
  text-align: center;
  color: #555555;
}

@media screen and (min-width: 768px) {
  .main-country-post-container .main-country-post-bg-image-container {
    height: 100%;
  }

  .main-country-top-layer .main-country-post-top-image-container {
    height: calc(100% - 120px);
  }

  .main-country-top-layer .main-country-icon-container {
    bottom: 80px;
  }

  .main-country-top-layer .main-country-icon-circle {
    padding: 8px;

    img {
      width: 72px;
      height: 72px;
    }
  }

  .main-country-top-layer .main-country-post-text-container {
    height: 100px;
    font-size: 20px;
    padding: 12px 24px;
  }
}

@media screen and (min-width: 1024px) {
  .main-country-post-container .main-country-top-layer .main-country-post-text-container {
    font-size: 24px;
  }
}
<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" href="path/to/MainCountryPost.css">
</head>
<body>
  <a href="/" class="main-country-post-container">
    <div class="main-country-post-bg-image-container">
      <img src="https://www.copahost.com/blog/wp-content/uploads/2019/07/imgsize2.png" alt="post-bg-image" />
    </div>
    <div class="main-country-top-layer">
      <div class="main-country-post-top-image-container">
        <img src="https://www.copahost.com/blog/wp-content/uploads/2019/07/imgsize2.png" alt="post-image" />
      </div>
      <div class="main-country-icon-container">
        <div class="main-country-icon-circle">
          <img src="https://www.copahost.com/blog/wp-content/uploads/2019/07/imgsize2.png" alt="icon" />
        </div>
      </div>
      <div class="main-country-post-text-container">
        some random text
      </div>
    </div>
  </a>
</body>
</html>

当我添加固定宽度和高度时:


  .main-country-top-layer {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    min-height: 200px;
    width: 500px;
    background: red;

My div appears, but I would like it to be responsive, not to use hardcoded values. enter image description here

推荐答案

问题出在显示器和高度上:

当我添加

.main-country-post-container {
  position: relative;
  cursor: pointer;
  display: inline-block; // new
  height: 100%; // new

它像预期的那样工作

Javascript相关问答推荐

fetch在本地设置相同来源的cookie,但部署时相同的代码不会设置cookie

使用TMS Web Core中的HTML模板中的参数调用过程

调用removeEvents不起作用

WebRTC关闭navigator. getUserMedia正确

查找最长的子序列-无法重置数组

简单的PayPal按钮集成导致404错误

实现JS代码更改CSS元素

在open shadow—root中匹配时,使用jQuery删除一个封闭的div类

在运行时使用Next JS App Router在服务器组件中运行自定义函数

如何使用JavaScript拆分带空格的单词

如何使用TypeScrip设置唯一属性?

同一类的所有div';S的模式窗口

为什么当我更新数据库时,我的所有组件都重新呈现?

判断函数参数的类型

构建器模式与参数对象输入

需要RTK-在ReactJS中查询多个组件的Mutations 数据

计算对象数组中属性的滚动增量

Firebase函数中的FireStore WHERE子句无法执行

Playwright:ReferenceError:browserContext未定义

已在EventListener中更新/更改异步的React.js状态对象,但不会导致组件重新呈现