【问题标题】:Image follow Background when resizing window screen调整窗口屏幕大小时图像跟随背景
【发布时间】:2019-01-08 09:39:58
【问题描述】:

我正在寻找一种方法来执行以下操作:

我的 HTML 页面上有两个部分,第一个在其 CSS 类中具有背景图像属性,并且在此部分底部还有一个徽标,我还有第二个部分,它只是一个普通部分,其中包含一些文本。

这张图显示了我当前使用的结构。

如果窗口屏幕被调整大小,标志图像必须跟随背景图像并保持其在图像底部的位置。

我尝试的最后一件事:

.background {
    background: url('../images/background-heroes.png') no-repeat;
    background-position: top center;
    background-size: 100% auto;
    position: fixed;
    width: 100%;
    height: 100%;
}

.background .logo {
    width: 20%;
    padding: 20% 0 5% 0;
    margin: 0 auto;
}

.background h1 {
    font-size: 3em;
    text-align: center;
    text-transform: uppercase;
    width: 100%;
}
<section class="background">
   <div class="logo">
     <img src="images/logo.png">
   </div>
   <h1>LIVE YOUR OWN ANIME!</h1>
</section>

不幸的是,我粘贴的这个解决方案使第二部分消失了。

【问题讨论】:

  • 特里,刚刚添加了我的最新尝试! :D

标签: javascript html css


【解决方案1】:

这似乎与您要完成的工作有关:

CSS

.background-image {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

HTML

<div class="background-image">
    <img class="logo">
</div>

<div class="another-section"></div>

【讨论】:

  • 只是提供了示例代码,因此该解决方案并不完美。希望 flex 属性仍然可以帮助您找到一个好的解决方案!
  • 感谢您的帮助!我刚刚添加了一个带有我当前使用的代码的 sn-p! :D 拜托,如果您现在有更好的解决方案,我将不胜感激。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-29
  • 1970-01-01
  • 2014-07-26
  • 1970-01-01
  • 2023-02-11
  • 1970-01-01
相关资源
最近更新 更多