html - 如何从主要内容制作带有背景的三 Angular 形

标签 html css

目前我的盒子看起来像这样:

enter image description here

我怎样才能让任何盒子里的背景图片影响到三 Angular 形,所以它看起来像这样? enter image description here

当我的代码看起来像这样的时候,我正在努力实现它。

.first,
.second,
.third {
  position: relative;
  display: block;
  height: 100px;
  padding: 20px;
}

.first {
  background: red;
}

.first:after {
  top: 100%;
  left: 50%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
  border-color: rgba(255, 0, 0, 0);
  border-top-color: red;
  border-width: 30px;
  margin-left: -30px;
  z-index: 2;
}

.second {
 background-image: url(http://az616578.vo.msecnd.net/files/2016/04/09/6359580807140768861266757027_Never-Study-Hard-The-Art-of-Studying-Smart.jpg);
 background-size: cover;
 background-repear: no-repeat;
}
.inner_second{
  background: blue;
  opacity; 0.8;
}

.second:after {
  top: 100%;
  left: 50%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
  border-color: rgba(0, 0, 255, 0);
  border-top-color: blue;
  border-width: 30px;
  margin-left: -30px;
  z-index: 2;
}

.third {
  background: yellow;
}
<div class="first">
  <div class="inner_first">
  </div>
</div>

<div class="second">
  <div class="inner_second">
  </div>
</div>

<div class="third">
  <div class="inner_third">
    
  </div>
</div>

希望能帮到你

最佳答案

你可以尝试使用 2 个伪元素 before a after.. 小 hack

.first,
.second,
.third {
  position: relative;
  display: block;
  height: 100px;
  padding: 20px;
}

.first {
  background: red;
}

.first:after {
  top: 100%;
  left: 50%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
  border-color: rgba(255, 0, 0, 0);
  border-top-color: red;
  border-width: 30px;
  margin-left: -30px;
  z-index: 2;
}

.second {
 background-image: url('http://az616578.vo.msecnd.net/files/2016/04/09/6359580807140768861266757027_Never-Study-Hard-The-Art-of-Studying-Smart.jpg');
 background-size: cover;
 background-repeat: no-repeat;
}
.inner_second{
  background: blue;
  opacity: 0.8;
}

.second::before {
  top: calc(100% - (30px * 2));
  left: 0;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 50%;
  position: absolute;
  pointer-events: none;
  border-color: rgba(0, 0, 255, 0);
  border-bottom-color: yellow;
  border-width: 30px;
  border-left-width: 0;
  z-index: 2;
  box-sizing: border-box;
}

.second::after {
  top: calc(100% - (30px * 2));
  right: 0;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 50%;
  position: absolute;
  pointer-events: none;
  border-color: rgba(0, 0, 255, 0);
  border-bottom-color: yellow;
  border-width: 30px;
  border-right-width: 0;
  z-index: 2;
  box-sizing: border-box;
}

.third {
  background: yellow;
}
<div class="first">
  <div class="inner_first">
  </div>
</div>

<div class="second">
  <div class="inner_second">
  </div>
</div>

<div class="third">
  <div class="inner_third">
    
  </div>
</div>

关于html - 如何从主要内容制作带有背景的三 Angular 形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44108587/

相关文章:

css - 如果浏览器现在可以缩放,我们为什么要使用 em 而不是 px?

jquery - 悬停后按钮的背景颜色消失

javascript - 如何在内容展开时更改 <div> 高度?

html - 下拉到页面底部

javascript - 围绕一个圆画几个数字

html - 如何在 CSS 中在另一个背景图像下显示背景图像

css - 在 Internet Explorer 9 中使用 -ms-filter

javascript - 背景图片占据整个屏幕

html - 如何更改 Angular ui-grid 中拖动工具(或)调整大小工具的颜色?

css - 另一种用于 flex 多列布局的非脚本解决方案,背景颜色扩展了整个滚动高度