html - 使英雄形象响应

标签 html css image bootstrap-4 responsiveness

我正在尝试让主页上的主图响应式响应,适用于桌面和移动设备。现在,它卡在页面的第二部分(在它下面),我尝试了不同的可能性来重新定位它,但我无法将它放在 masterhead 的中心......任何提示将不胜感激,我不知道该做什么或我做错了什么 :-/

这是 HTML:

<!-- Masthead -->
  <header class="masthead bg-primary image-center">
    <div class="container d-flex align-items-center flex-column">

    <!--Background Particles-->
      <div id="particles-js"></div>

      <!--Hero Image-->
      <img class="masthead-logo mb-5" src="https://pandassi.github.io/website.github.io/hero.png" alt="Lila Ait">

</div>

  </header>

对于 CSS:

.bg-primary {
  background: radial-gradient(#49a7b7, #293f50) !important;
  height: 35em;
}

然后:

/*Just for info, I am using a Boostrap framework, not sure the purpose of mb-5 but I didn't want to mess with it*/

.mb-5,
.my-5 {
  margin-top: 3rem !important;
  margin-bottom: 3rem 

还有一点:

#particles-js {
  width: 80rem;
  height: 35em;
  margin-top: -12.5rem !important;
}

.masthead {
  padding-top: calc(6rem + 74px);
  padding-bottom: 6rem;
}

.masthead .masthead-heading {
  font-size: 2.75rem;
  line-height: 2.75rem;
}

.masthead .masthead-subheading {
  font-size: 1.25rem;
}

.masthead .masthead-logo {
  width: 25rem;
}

.masthead-logo {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1;
}


@media (min-width: 992px) {
  .masthead {
    padding-top: calc(6rem + 104px);
    padding-bottom: 6rem;
  }
  .masthead .masthead-heading {
    font-size: 4rem;
    line-height: 3.5rem;
  }
  .masthead .masthead-subheading {
    font-size: 1.5rem;
  }
  .masterhead-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  }
}

最佳答案

在 Bootstrap 中有一个使图像响应的类。它的 class=img-fluid 并将您的图像定位到页面的中心,您可以将其应用于图像

img{
position: absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%)
}

关于html - 使英雄形象响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56586579/

相关文章:

html - 如果在 HTML 5 中找不到图像,如何显示默认图像

jQuery动态图片加载

python - 图像在 Django 运行服务器上不以 HTML 呈现,但 HTML 在浏览器中工作

html - Node.js HTML 和 CSS

javascript - 如何使用 jquery 克隆多个 html 输入字段

css - 设置权重时的@font-face 问题

javascript - SVG 缩放 - 窗口高度或宽度的百分比

javascript - 为什么 MutationObserver 代码不能在 Chrome 30 上运行?

javascript - 只有在左上方找到图片后才会出现包含信息的框

CSS :not pseudo class is not taking effect