html - 沿对 Angular 线拆分为 3 个 div

标签 html css

尝试实现图片所示的效果,但不确定什么是最佳方法,因为我想在悬停时调整 div 高度。

容器 div 必须为 100% 宽度、100% 高度并且内部的 div 必须完全响应。

边框、伪造或背景不适用于这种特殊情况。

enter image description here

html

<div class="container">
  <div class="top"></div>
  <div class="center">
    <p>text text</p>
  </div>
  <div class="bottom"></div>
</div>

CSS

.container{
      width: 100%;
      height: 100vh;
      overflow: hidden;
     //  transform: skewY(-45deg);
     //  transform: rotate(-45deg);
}
.top, .bottom {
    width: 100%;
    height: calc(50% - 20px);
}
.top {
    background: black;
}
.bottom {
    background: grey;
}
.center {
    background: green;
    height: 40px;
    width: 100%;
}
p {
  color: white;
  line-height: 10px;
  text-align: center;
}

jsfiddle你会发现 rotate 和 skewY 都有注释。

最佳答案

希望它对你有用。

如果想要纯 CSS 解决方案,您可以试试这个。 它使用 Area of​​ Traingle 和所有其他计算。 我已经将 width: 300px;height:600px; 给了 parent DIV 然后进行了计算。您可能需要相应地进行更改。 我使用 SCSS 来编写我的 CSS,所以这对我来说很容易。尽管我已经尝试使用 calc 进行更多计算以使其对 CSS 更友好。

.parent {
  position: relative;
  width: 300px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 600px;
  /* Not relevant. this was used to show a Guide-point of intersection of one of triangle's side. 
  &:before {
    content: '';
    width: 2px;
    height: 2px;
    background: #000;
    position: absolute;
    left: calc(50% - 1px);
    top: -1px;
    display: block;
  }
  &:after {
    content: '';
    width: 2px;
    height: 2px;
    background: #000;
    position: absolute;
    left: calc(50% - 1px);
    bottom: -1px;
    display: block;
  }
  */
}

.child {
  min-height: 20px;
  padding: 15px;
  transform: skewY(-30deg);
  transition: all 0.2s ease;
  display: flex;
  align-content: center;
  align-items: center;
}

.child:hover {
  height: calc(100% - 40px);
}

.child:hover~.child {
  height: 20px;
}

.child__inner {
  transform: skewY(30deg);
  color: #fff;
}

.child--top {
  background: tomato;
  height: calc(50% - 20px);
  margin-top: calc((150px / 1.73)* -1);
  padding-top: calc((150px / 1.73) * 2);
}

.child--middle {
  background: DeepSkyBlue;
}

.child--bottom {
  background: MediumSeaGreen;
  height: calc(50% - 20px);
  margin-bottom: calc((150px / 1.73)* -1);
  padding-bottom: calc((150px / 1.73) * 2);
}
<div class="parent">
  <div class="child child--top">
    <div class="child__inner">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus, accusantium. Illo minima ipsa, at dignissimos perspiciatis nesciunt. Hic quae porro assumenda possimus fugit, velit eaque magni, reiciendis veritatis perspiciatis recusandae?
    </div>
  </div>
  <div class="child child--middle">
    <div class="child__inner">

    </div>
  </div>
  <div class="child child--bottom">
    <div class="child__inner">

    </div>
  </div>
</div>

如果你想检查SCSS,下面是代码。

.parent {
  position: relative;
  width: 300px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 600px;
  /* Not relevant. this was used to show a Guide-point of intersection of one of triangle's side. 
  &:before {
    content: '';
    width: 2px;
    height: 2px;
    background: #000;
    position: absolute;
    left: calc(50% - 1px);
    top: -1px;
    display: block;
  }
  &:after {
    content: '';
    width: 2px;
    height: 2px;
    background: #000;
    position: absolute;
    left: calc(50% - 1px);
    bottom: -1px;
    display: block;
  }
  */
}

.child {
  min-height: 20px;
  padding: 15px;
  transform: skewY(-30deg);
  transition: all 0.2s ease;
  display: flex;
  align-content: center;
  align-items: center;

  &:hover {
    height: calc(100% - 40px);
  }
  &:hover ~ .child {
    height: 20px;
  }
  &__inner {
    transform: skewY(30deg);  
    color: #fff;
  }
  &--top {
    background: tomato;
    height: calc(50% - 20px);
    margin-top: calc((150px / 1.73)* -1);
    padding-top: calc((150px / 1.73) * 2);
  }
  &--middle {
    background: DeepSkyBlue;
  }
  &--bottom {
    background: MediumSeaGreen;
    height: calc(50% - 20px);
    margin-bottom: calc((150px / 1.73)* -1);
    padding-bottom: calc((150px / 1.73) * 2);
  }
}

引用:Area of Traingle and Sides height/width

关于html - 沿对 Angular 线拆分为 3 个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43625360/

相关文章:

html - Bootstrap 分隔符在较小的屏幕上移位

jquery - 为什么 .remove() 在我的设置中不起作用?

html - 在 CSS 中的特定位置对齐当前行的输入

Javascript循环/递增值最大为55的html代码

jQuery fadeTo() 在 IE 9 中使用 Shadow Filter 创建黑框

jquery - 用户控制的 CSS 选择器是否需要清理?

html - 创建透明加载叠加层

c# - 修复网络浏览器内容的不同文本量

javascript - 如何将表单提交的日期/时间推送到 Firebase 数据库

javascript - HTML5 游戏引擎 - JavaScript 动画