Search code examples
htmltwitter-bootstrapcssdiagonal

how to make shape with diagonal div?


I want to make this shape : enter image description here there supposed to be 3 div shapes like this. I built already some shape, but I want to see how this shape will fit in my website

I already built this : codepan

css example for what i did :

.mainOuterDiv{

    height:300px;

    overflow:hidden;
    background:#FFF;
}
.middDiv{
    width:70%;
    height:75px;
    background-color: #0CF;
    margin:0px auto;
    position:relative;
    margin-top:50%;
}
.innerLeft{
    position: absolute;
    left: -60px;
    top: -20px;
    width: 60px;
    height: 100%;
    z-index: 1;
    transform: skew(180deg,215deg);
    background-color: #0CF;
}
.innerRight{
    position: absolute;
    right: -60px;
    top: -20px;
    width: 60px;
    height: 100%;
    z-index: 1;
    transform: skew(180deg,145deg);
    background-color: #0CF;
}
.textDiv{
    z-index:9999;
    width:100%;
    height:100%;
    position:absolute;
    background-color: #0CF;
}

is there a way to make this in css ?


Solution

  • There is some example :

    .container
    {
      position:relative;
      width:400px; height:302px;
      overflow:hidden;
    }
    .mainDiv
    {
      height:300px; width:300px;
      background-color:white;
      border:solid 1px black;
      position:absolute;
      left:0;right:0;margin:auto;
    }
    .middDiv
    {
      height:55px; width:70%;
      background-color:lightblue;
      position:absolute;
      bottom:0;left:0;right:0;
      margin:auto;
      z-index:10;
    }
    .leftDiv, .rightDiv
    {
      position:absolute;
      bottom:26px;
      width:30%;height:48px;
      background-color:blue;
      z-index:10;
    }
    .leftDiv 
    {
      left:-13%;
      transform:rotate(30deg) skew(30deg);
    }
    .rightDiv
    {
      right:-13%;
      transform:rotate(-30deg) skew(-30deg);
    }
    .leftBDiv, .rightBDiv
    {
      position:absolute;
      width:13%; height:47px;
      bottom:59px;
      background-color:black;
      z-index:9;
    }
    .leftBDiv
    {
      left:-12%;
      transform:rotate(-30deg) skew(-30deg);
    }
    .rightBDiv
    {
      right:-12%;
      transform:rotate(30deg) skew(30deg);
    }
    <div class="container">
      <div class="mainDiv">
        <div class="middDiv"></div>
        <div class="leftDiv"></div>  
        <div class="rightDiv"></div>
        <div class="leftBDiv"></div>
        <div class="rightBDiv"></div>
      </div>
    </div>

    I use different colors for middle, left and right blocks so You can see it.

    If You will use border for those divs, You have to change positions: left, right and bottom for all of them.

    There is fiddle example, too.