CSS如何平滑两个标题之间的过渡

史提芬

我有一个包含标题的项目。该标题由特定的背景颜色和文本颜色组成。这些颜色与网站的一部分配合不佳。所以我想将标题转换为不同的颜色。但是我希望颜色在边界处逐渐改变,而不是立即交换。

进出容器时,标头应在容器的边界从一种颜色转换为另一种颜色。但是我似乎没有使它起作用。

在此处输入图片说明

body {
  height: 300rem;
  margin: 0;
  padding: 0;
}

#main-container {
  width: 100%;
  height: 100%;
  background-color: red;
}

#header {
  width: 100%;
  height: 2rem;
  background-color: blue;
  position: sticky;
  top: 0;
}

#someDiv {
  position: relative;
  width: 100%;
  height: 20rem;
  background-color: purple;
  margin-top: 30rem;
}

#headerSomeDiv {
  width: 100%;
  height: 2rem;
  background-color: green;
  color: white;
  position: sticky;
  top: 0;
}
<body>
    <div id="main-container">
        <div id="header">
            <h1>HEADER</h1>
        </div>
        <div id="someDiv">
            <div id="headerSomeDiv">
                <h1>HEADER</h1>
            </div>
        </div>
    </div>
</body>

陪同Afif

position:fixed 可以做到这一点

body {
  height: 300rem;
  margin: 0;
}

#main-container {
  height: 100%;
  background-color: red;
  clip-path:inset(0); /* to clip the position:fixed to its container */
  overflow:auto;
}

#header,
#headerSomeDiv{
  width: 100%;
  height: 2rem;
  background-color: blue;
  position: fixed;
  top: 0;
}

#headerSomeDiv {
  background-color: green;
  color: white;
}
h1 {
  margin:0;
}
#someDiv {
  position: relative;
  height: 20rem;
  background-color: purple;
  margin-top: 30rem;
  clip-path:inset(0); /* to clip the position:fixed to its container */
}
<body>
  <div id="main-container">
    <div id="header">
      <h1>HEADER</h1>
    </div>
    <div id="someDiv">
      <div id="headerSomeDiv">
        <h1>HEADER</h1>
      </div>
    </div>
  </div>
</body>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Vue / CSS,如何在两个交替元素之间进行平滑的高度过渡(包括小提琴)

两个元素“跳跃”之间的平滑过渡

如何在SceneKit中的两个单独的动画之间平滑过渡?

CSS动画中两个步骤之间的平滑转换

使用gganimate在两个时间序列条形图之间创建平滑过渡

如何找到两个角度之间的最小过渡

两个imageview之间的动画过渡

两个NSDate之间的过渡日

如何计算两个小标题之间的差异?

如何平滑CSS关键帧之间的过渡

如何在reStrutureText的列表中的标题和标题之间插入两个空行?

如何在两个HTML页面之间进行过渡效果

如何在脚本中使用bool参数在两个动画之间开始过渡?

在首先等待子组件过渡/动画完成时,如何在两个nuxt页面之间过渡?

CSS:数组元素之间的平滑过渡

两个视图之间的自定义循环过渡

两个div元素之间的vue2过渡

如何减少CSS中两个元素之间的间距?

如何使用CSS在两个渐变之间创建曲线?

如何在两个不同的 css 动画之间交替

如何在html / css中为两个div设置动画以进行半圆过渡?

如何为多个CSS转换设置两个过渡持续时间

如何返回两个标题行?

如何使用scrollIntoView()同时平滑滚动两个元素?

如何使同步两个Divs滚动位置更平滑

正则表达式:如何在两个标题之间选择所有内容?

如何提取以特定字符开头的两个标题之间的行?

如何在两个标题之间适合并自动移动和缩放图像?

XPath获取两个标题之间的标记