【问题标题】:How to pass background-size and background-position inside the background-image url() [duplicate]如何在背景图像url()中传递背景大小和背景位置[重复]
【发布时间】:2021-06-05 05:51:28
【问题描述】:

我有一个 div,我在其中设置了 background-image url() 我的问题是我想实现这样的目标 background-image url('example') cover center

目前,我的代码如下所示

div {
   background-image: url(example);
   background-size: cover;
   background-position: center;
}

正如我之前提到的,我想实现这样的目标

div {
   background-image: url(example) cover center;
}

【问题讨论】:

    标签: html css styles background-image


    【解决方案1】:

    您应该可以在此处找到 css 背景图像效果以及如何居中并使图像适合屏幕封面的参考:https://www.w3schools.com/htmL/html_images_background.asp

    我会尝试使用下面的代码,它可能会解决您的问题:

    .yourDiv {
      background-image: url('Background URL here');
      background-repeat: no-repeat;
      background-attachment: fixed;
      background-size: 100% 100%;
    }
    

    【讨论】:

      【解决方案2】:

      background-image 仅支持图像,这样您就可以使用过滤器覆盖它们。无法直接说出它应该是什么样子。为此,您仍然必须使用 background-size 和 background-position

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-09
        • 1970-01-01
        • 2014-09-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-05
        • 2021-03-14
        相关资源
        最近更新 更多