【问题标题】:Background position, margin-top?背景位置,边缘顶部?
【发布时间】:2022-02-22 20:27:39
【问题描述】:

我目前将我的背景设置为右上角:

#thedivstatus {
    background-image: url("imagestatus.gif");
    background-position: right top;
    background-repeat: no-repeat;
}

但是!我需要添加一个 margin-top:50px; 从上面的渲染位置。谁能给我一个建议?

谢谢

【问题讨论】:

  • 嗯?您的意思是您需要在任何内容之前将背景拉伸 50 像素?那将是padding-top。否则,你的问题绝对没有意义。
  • 我的意思是,我希望背景图片从默认的“右上角”css 放置的位置向下 50 像素放置。

标签: css


【解决方案1】:

如果您的意思是希望背景图像本身从顶部偏移 50 像素,例如背景边距,那么只需将 top 切换为 50px 即可。

#thedivstatus {
    background-image: url("imagestatus.gif");
    background-position: right 50px;
    background-repeat: no-repeat;
}

【讨论】:

  • 你也可以这样计算百分比吗?
  • 好吧。它只有左右两个选项。这与 X 轴和 Y 轴相关联。所以如果你想从上往下改变值,你需要从右向左改变。
  • 简单易行!非常感谢,非常有帮助!
【解决方案2】:
 background-image: url(/images/poster.png);
 background-position: center;
 background-position-y: 50px;
 background-repeat: no-repeat;

【讨论】:

  • 虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。
【解决方案3】:

在导航栏中工作,在 GrapesJs 中添加图像。在拆分中显示图像

.gjs-block-navbar1{
width: 100%;
height:auto;
background-image: url("./assets/images/navbar/navbar-1.png");
background-repeat: no-repeat;
background-position:center 0px;
background-size:cover;
}

在侧边栏中图像修复以显示中心并清除

【讨论】:

    【解决方案4】:
    #div-name
    
    {
    
      background-image: url('../images/background-art-main.jpg');
      background-position: top right 50px;
      background-repeat: no-repeat;
    }
    

    【讨论】:

    猜你喜欢
    • 2014-07-07
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    相关资源
    最近更新 更多