【问题标题】:4 Triangle in a box with image inside4 盒子里的三角形,里面有图片
【发布时间】:2017-03-25 17:28:25
【问题描述】:

我需要帮助在 CSS / jQuery / SVG / Canvas 中创建类似上图的内容

每个三角形都将包含一个需要裁剪以适合三角形的图像,并且所有内容都需要响应。

我通过 CSS 边框做到了这一点,但令我惊讶的是,我无法向其中添加图像。

非常感谢任何类型的提示或信息。

通过 CSS 生成的示例:

<div class="middle_section" style="height: 900px;">
    <div class="one_forth triangleMask for_1"></div>
    <div class="one_forth triangleMask for_2"></div>
    <div class="one_forth triangleMask for_3"></div>
    <div class="one_forth triangleMask for_4"></div>
</div>
.middle_section .for_3,
    .middle_section .for_1{
        width: 100%;
        height: 50%;
        overflow: hidden;
    }

    .middle_section .for_2,
    .middle_section .for_4{
        width: 50%;
        height: 100%;
        overflow: hidden;
    }

    .middle_section .for_1:after {
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 440px 808px 0px 808px;
        border-color: #ff0000 transparent transparent transparent;
        content: '';
        position: absolute;
        top:0;
        left:10px;
    }

    .middle_section .for_2:after {
        width: 0;
        height: 0;
        border-top: 440px solid transparent;
        border-bottom: 440px solid transparent;
        border-left: 808px solid lime;
        content: '';
        position: absolute;
        top:10px;
    }

    .middle_section .for_3:after {
        width: 0;
        height: 0;
        border-left: 808px solid transparent;
        border-right: 808px solid transparent;
        border-bottom: 440px solid #4679BD;
        content: '';
        position: absolute;
        bottom:0;
        left:10px;
    }

    .middle_section .for_4:after {
        width: 0;
        height: 0;
        border-top: 440px solid transparent;
        border-bottom: 440px solid transparent;
        border-right: 808px solid pink;
        content: '';
        position: absolute;
        top:10px;
        right:0;
    }

【问题讨论】:

  • 你能分享你的代码吗?
  • 你能提供你的试用代码
  • 以上代码更新
  • 感谢您的代码,但您的问题是什么?你说你想做某事,发布代码,但代码是做什么的?为什么它不起作用?这段代码的问题在哪里?
  • 嗨,阿德里安,感谢您的帮助,问题是我无法在三角形内添加图像

标签: javascript jquery css canvas svg


【解决方案1】:

我用 CSS 变换旋转做了一个例子:

.wrapper {
  width:284px;
  height:281px;
  overflow: hidden;
  position: relative;
}

.top {
  transform: rotate(45deg);
  position: absolute;
  top:-100px;
  left: 40px;
}

.bottom {
  transform: rotate(45deg);
  position: absolute;
  bottom: -105px;
  left: 40px;
}

.left {
  transform: rotate(45deg);
  position: absolute;
  left: -102px;
  top: 41px;
}

.right {
  transform: rotate(45deg);
  position: absolute;
  right: -98px;
  top: 41px;
}
<div class="wrapper">

  <div class="top">
     <img src="http://lorempixel.com/200/200/sports/1"/>
  </div>
  
  <div class="bottom">
     <img src="http://lorempixel.com/200/200/sports/2"/>
  </div>
  
  <div class="left">
     <img src="http://lorempixel.com/200/200/sports/3"/>
  </div>
  
  <div class="right">
     <img src="http://lorempixel.com/200/200/sports/5"/>
  </div>
  
</div>

【讨论】:

  • 嘿,是的,但这是无响应的 :( 并且图像被旋转
猜你喜欢
  • 2022-07-06
  • 1970-01-01
  • 2014-03-28
  • 2011-11-18
  • 1970-01-01
  • 1970-01-01
  • 2014-08-21
  • 1970-01-01
相关资源
最近更新 更多