【问题标题】:I can not use position fixed and linear gradient at the same time. why is it? [duplicate]我不能同时使用位置固定和线性渐变。为什么? [复制]
【发布时间】:2021-02-03 13:49:02
【问题描述】:

我对编码知之甚少,这实际上是一项学校作业。我想在我的背景是渐变的时候使用position:fixed,但是当我使用position:fixed时,我的背景渐变消失了。

body{
      height: 92vh;
      margin-top: 60px;
      width: 100%;
      /*position: fixed; Probem when added*/
      background-image: linear-gradient(rgb(204, 63, 142), rgb(9, 78, 195));
    }

我猜是背景图片有问题

【问题讨论】:

  • <body> 不需要修复。

标签: css linear-gradients


【解决方案1】:

这能解决你的问题吗:代替position: fixed;试试background-attachment: fixed;

body{
  height: 92vh;
  margin-top: 60px;
  width: 100%;
  /*position: fixed;*/
  background-attachment: fixed;
  background-image: linear-gradient(rgb(204, 63, 142), rgb(9, 78, 195));
}
<body>
</body>

是的,请参阅@david-ngumbu 的答案以获得更好的线性渐变规范;)

来源:Fixed gradient background with css

【讨论】:

    【解决方案2】:

    我只是想添加到@zerbene 的答案您还必须指定线性渐变的方向例如linear-gradient(to bottom, rgb(204, 63, 142), rgb(9, 78, 195)) 将设置渐变方向从顶部到底部示例2:linear-gradient(to right, rgb(204, 63, 142), rgb(9, 78, 195)) 它将设置@987654323 @ 从左到右。您还可以像 linear-gradient(45deg, rgb(204, 63, 142), rgb(9, 78, 195)) 这样为线性渐变添加度数。

    【讨论】:

    • 默认为to bottom
    • 还是建议将to bottom添加到线性渐变中,尽管它是默认值。
    猜你喜欢
    • 2020-11-06
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 2011-01-17
    • 1970-01-01
    • 2012-10-14
    • 2020-11-09
    相关资源
    最近更新 更多