html - CSS Clip - 允许背景显示

标签 html css

我正在尝试将 css 剪辑应用于元素以允许后面的图层显示出来。我有以下布局..

body, html {
  margin:0;
  padding:0;
}

.container {
background:lightgray;
}

.clip {
  position:fixed;
  height:100%;
  width:100px;
  clip: rect(10px, 100px, 100px, 100px);
}

.section1, .section2 {
  height:100vh;
  width:100%;
}

.section_left_red {
  height:100%;
  width:100px;
  background:red;
}

.section_left_blue {
  height:100%;
  width:100px;
  background:blue;
}
<div class="container">

<div class="clip">
</div>

<div class="section1">
<div class="section_left_red">
</div>
<div>

<div class="section2">
<div class="section_left_blue">
</div>
<div>

</div>

我正在努力实现这样的目标..

enter image description here

所以当我向下滚动时,蓝色背景就会显示出来。谁能告诉我我做错了什么?

最佳答案

您可以使用多个背景来创建它。这个想法是只对背景的一部分着色,使其余部分透明:

body,
html {
  margin: 0;
  padding: 0;
}

.clip {
  position: fixed;
  height: 100%;
  width: 200px;
  box-sizing:border-box;
  border:5px solid lightgray;
  background: 
    linear-gradient(lightgray,lightgray) right/50% 100%,
    linear-gradient(lightgray,lightgray) bottom/100% 80%;
  background-repeat:no-repeat;
}

.section1,
.section2 {
  height: 100vh;
  width: 100%;
  background: red;
}

.section2 {
  background: blue;
}
<div class="container">

  <div class="clip">
  </div>

  <div class="section1">
  </div>

  <div class="section2">
  </div>

</div>

关于html - CSS Clip - 允许背景显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52987172/

相关文章:

Android - 从网站解析文本

html - 模式关闭时停止在 iframe 中播放视频

html - 当网页缩小时使图像堆叠

html - <li> 标签内的图片

javascript - jQuery 动画影响下面的内容 (Chrome)

html - ng-grid 标题单元格中的文字换行

javascript - Vanilla Javascript 单击并关闭导航

html - 如何使用 CSS 设置 "\n"的样式?

javascript - 如何在使用 jquery 单击一次后禁用链接

javascript - 使用 css 或 javascript 进行响应式网页设计?