【问题标题】:Set a background image width & height, with aspect ratio [duplicate]设置背景图像的宽度和高度,具有纵横比[重复]
【发布时间】:2018-02-27 10:15:22
【问题描述】:

我在这个论坛和互联网上搜索解决方案,大多数解决方案都可用,但对我的情况没有任何作用......或者我可能不明白。

我有一张背景图片,我希望它采用 100% 的宽度和相同的高度值。

.top-section {
  background: url('../img-content/Bg1.png') no-repeat center center fixed;
  background-size: cover;
}
<div class="top-section"></div>

【问题讨论】:

    标签: html css


    【解决方案1】:
    html, body {   height: 100%; }
    
    .top-section {    
      width: 100%;   
      height: 100%;   
      background-image: url("'../img-content/Bg1.png");   
      background-attachment: fixed;   background-size: cover; 
    }
    

    其他图片使用类似

    .top-section2 {
      width: 100%;   
      height: 100%;   
      background-image: url("");
      background-size: cover;
    }
    

    【讨论】:

    • 不要占我身高的100%,如果你愿意,我给你发截图
    • @Jonathan 发给我
    • 更新,用这个?
    • 同样的结果,我之前尝试过这个解决方案...我无法解决我的问题我不明白为什么
    猜你喜欢
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    • 2011-12-24
    相关资源
    最近更新 更多