html - 使用 CSS 从 div 顶部开始循环 "cut-away"

标签 html css

<分区>

我正在尝试在 CSS 中创建以下布局。

enter image description here

这通常很容易做到,但是因为背景是一个图像(在我的图像中显示为渐变),我不能简单地在顶部添加一个绝对定位的 div 并为“切掉”着色。在过去的几个小时里,我一直在努力想出如何做到这一点。

我已经查找了一些使用 ::before::after 伪选择器的示例,但是无法弄清楚如何在保持边框半径的同时做到这一点在主要内容 div(蓝色)上。

<div class="content">
<div class="header">
  <a class="left" href="#">LINK 1</a>
  <!--
  Stuck with how to position this so it clips
  <img class="logo" src="https://placehold.it/100x100">
  -->
  <a class="right" href="#">LINK 2</a>
</div>

<p>Some text content</p>

.content {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 20px;
  background-color: blue;
  height: 300px;
  width: 400px;
  padding: 20px;
}

.header {
  position: relative;
  top: -50px;
  padding: 0 20px;
}

.header .right {
  float: right;
}

演示:http://jsbin.com/saxunecidu/1/edit?html,css,output

最佳答案

用于救援的径向渐变!

#test{
  padding:10px;
  background:rgb(100,100,240);
  color:white;
  font-size:25px;
  -webkit-mask-image: radial-gradient(circle at top, transparent 30px, black 31px);
  border-radius:15px;
  width:600px;
  height:150px;
  margin:10px;
}
body{
  background: radial-gradient(lightgrey,black);//just an example gradient
}
<div id="test">Something there</div>

关于html - 使用 CSS 从 div 顶部开始循环 "cut-away",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37644944/

相关文章:

html - ion-col 中的嵌套 div,100% 高度在 IOS 中不起作用

javascript - 将创建的 div 调整为父 div

html - 在angularjs中使用ng-hide时如何解决总和问题?

CSS Attribute Selector : Apply class if custom attribute has value? 另外,它能在 IE7+ 中工作吗?

javascript - SlideUp 上升,虽然选择的类还没有离开

javascript - 如何在 mozilla firefox 中使用 jquery 缩放网页正文

html - 拉伸(stretch) flexbox child 以填充列高度

html - 为什么文本在html结构中包含在父元素中,但在浏览器中溢出了父元素?

css - 使用不同的媒体查询方法的响应式布局行为

javascript - CSS 过渡结合 JS clickEvent