3

I've see a lot of threads remotely related that basically suggest CSS triangles in the ::after or ::before pseudos, but none have really panned out. I'm throwing this out to see if anyone has any ideas.

I'm looking to create a div with a pointed or pitched top that still maintains a uniform border and box-shadow with the rest of the div.

See link for an image of what I'm trying to create:

enter image description here

web-tiki
  • 99,765
  • 32
  • 217
  • 249
scannon
  • 31
  • 2

2 Answers2

2

If you dont want to use a image you could do something like this. But working with an image is lot easier in this case.

body {
    background-color: #CCC;
}

.wrapper {
    
}

.outer {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 205px 32px 205px;
    border-color: transparent transparent #ffffff transparent;
    position: absolute;
}

.inner {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 200px 32px 200px;
    border-color: transparent transparent #ea2225 transparent;
    margin-left: -200px;
    margin-top: 5px;
    position: absolute;
}

.fix {
    background-color: #FFF;
    height: 10px;
    width: 410px;
    position: absolute;
    margin-top: 32px;
}

.red {
    width: 396px;
    height: 300px;
    background-color: #ea2225;
    margin-top: 37px;
    position: absolute;
    border-left: 7px solid #FFF;
    border-right: 7px solid #FFF;
    border-bottom: 6px solid #FFF;
-webkit-box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
-moz-box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
}
<div class="wrapper">
     <div class="fix"></div>
<div class="outer">
   
  <div class="inner"> 
    
  </div>
    
</div>
  
</div>
   <div class="red"></div>

See http://jsfiddle.net/0csqog8s/

S.Visser
  • 4,645
  • 1
  • 22
  • 43
1

this should get you started:

Update

This is an updated fiddle which is much better presented.

.first {
  display: inline-block;
  width: 3em;
  height: 3em
}
.second {
  position: relative;
  display: inline-block;
  width: 3em;
  height: 3em
}
.third {
  position: absolute;
  display: inline-block;
  width: 0;
  height: 0;
  line-height: 0;
  border: 1.5em solid transparent;
  margin-top: -1em;
  border-bottom: 1em solid #007BFF;
  left: 0em;
  top: 0em
}
.forth {
  position: absolute;
  display: inline-block;
  width: 0;
  height: 0;
  line-height: 0;
  border: 1.5em solid #007BFF;
  border-bottom: 1.5em solid #007BFF;
  left: 0em;
  top: 1.5em
}
<span class="first"><span class="second"><i class="third"></i><i class="forth"></i></span></span>
jbutler483
  • 24,074
  • 9
  • 92
  • 145
  • 1
    the problem with the border technique to create the triangle is that you can't give the shape a border or box-shadow – web-tiki Nov 19 '14 at 13:20
  • 1
    if old browsers are not important he could create the top of the triangle with two elements that are rotated. that would fix the issue with the border or the box-shadow. – hurrtz Nov 19 '14 at 13:26