CSS“位置:固定”滚动文本重叠问题

基里尔

在这种情况下如何避免标题文本重叠?又为什么对上半部分隐藏溢出而对下半部分可见溢出?

演示:https : //jsfiddle.net/sftrq1hv/

body {
  margin: 0;
}

section.hero {
  position: relative;
  height: 100vh;
  overflow:hidden;
}

section.hero h1 {
  display: block;
  position: fixed;
  text-align: center;
  width: 100%;
  top: 50%;
}

section :first-child {
  margin-top: 0;
}

.bg1 {
  background: yellow;
}

.bg2 {
  background: cyan;
}

.bg3 {
  background: magenta;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Demo</title>
</head>

<body>
  <section class="hero bg1">
    <h1 class="hero-title">0</h1>
  </section>
  <section class="hero bg2">
    <h1 class="hero-title">1</h1>
  </section>
  <section class="hero bg3">
    <h1 class="hero-title">2</h1>
  </section>
</body>

</html>

陪同Afif

应用clip-pathmask隐藏position:fixed溢出将不起作用position:fixed

body {
  margin: 0;
}

section.hero {
  position: relative;
  height: 100vh;
  clip-path:polygon(0 0,100% 0,100% 100%,0 100%);
  /*OR
   -webkit-mask:linear-gradient(#fff,#fff);
           mask:linear-gradient(#fff,#fff);
  */
}

section.hero h1 {
  display: block;
  position: fixed;
  text-align: center;
  width: 100%;
  top: 50%;
}

section :first-child {
  margin-top: 0;
}

.bg1 {
  background: yellow;
}

.bg2 {
  background: cyan;
}

.bg3 {
  background: magenta;
}
<section class="hero bg1">
  <h1 class="hero-title">0</h1>
</section>
<section class="hero bg2">
  <h1 class="hero-title">1</h1>
</section>
<section class="hero bg3">
  <h1 class="hero-title">2</h1>
</section>

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

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

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

位置固定重叠的问题?

来自分类Dev

CSS3简单的文本动画,滚动时与固定的导航栏重叠,尽管文本的内容区域没有?

来自分类Dev

位置平滑滚动问题:固定;

来自分类Dev

Safari“位置:固定”在滚动条上重叠

来自分类Dev

检测静态元素何时与滚动上的固定元素位置重叠

来自分类Dev

CSS固定位置菜单-调整浏览器大小时出现滚动问题

来自分类Dev

CSS div跨度位置文本重叠

来自分类Dev

位置:固定重叠页面

来自分类Dev

固定位置时macgap滚动问题

来自分类Dev

仅限Chrome:滚动固定div时出现固定位置滚动问题

来自分类Dev

位置绝对,但滚动固定

来自分类Dev

剖面位置:固定重叠页脚

来自分类Dev

位置固定元素与页脚重叠

来自分类Dev

css相对位置并滚动时固定在顶部

来自分类Dev

CSS使背景图像位置固定并向上滚动内容

来自分类Dev

HTML / CSS:滚动div而不将位置设置为固定或绝对

来自分类Dev

HTML / CSS:滚动div而不将位置设置为固定或绝对

来自分类Dev

CSS位置:滚动时固定在左侧或顶部

来自分类Dev

滚动时,UITextView的文本重叠

来自分类Dev

位置相对重叠位置固定

来自分类Dev

CSS图片重叠问题

来自分类Dev

Divs的CSS重叠问题

来自分类Dev

图像重叠与CSS问题

来自分类Dev

固定位置div的CSS溢出问题

来自分类Dev

文本后的 Bootstrap CSS 按钮固定位置

来自分类Dev

固定位置不可滚动

来自分类Dev

div图像位置固定+滚动

来自分类Dev

javascript固定在滚动位置

来自分类Dev

滚动上的“位置:固定”图像