2

I have a triangle in the top left corner of my site

#corner {
  position: absolute;
  z-index: 999;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-top: 50px solid #000;
  border-bottom: 50px solid transparent;
  border-right: 50px solid transparent;
  border-left: 50px solid #000;
}
<div id="corner"></div>

EDIT - I want it to have a 5px red border (only on the angled side) so the triangle and the border are different colors

Ideally it will have a .png image over-top as well, but I can put another div over-top if need be

This is a corner triangle for the whole page

user3550879
  • 3,389
  • 6
  • 33
  • 62

3 Answers3

2

Create two divs:

#corner {
  position: absolute;
  z-index: 999;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-top: 55px solid #f00;
  border-bottom: 55px solid transparent;
  border-right: 55px solid transparent;
  border-left: 55px solid #f00;
}

#corner-inner {
  position: absolute;
  z-index: 999;
  left: -55px;
  top: -55px;
  width: 0;
  height: 0;
  border-top: 50px solid #000;
  border-bottom: 50px solid transparent;
  border-right: 50px solid transparent;
  border-left: 50px solid #000;
}
<div id="corner">
    <div id="corner-inner"></div>
</div>
  • I assume this is the best response, I just have to put a logo overtop as well, and I don't want to stack to many divs – user3550879 Jul 23 '16 at 03:35
  • Yeah, so far... I think that's as simple as it's goning to get. I couldn't work how to do this any other way. –  Jul 23 '16 at 03:37
1

I believe the best way to achieve what you want is to use the transform property instead of manipulating the border and possibly even needing two elements and a lot of unnecessary code.

Check out this fiddle or the following snippet for a visual representation.

Snippet:

#corner {
  /* Dimensions */
  height: 200px;
  width: 200px;
  
  /* Positioning */
  position: absolute;
  left: -7.5em;
  top: -7.5em;
  z-index: 999;
  transform: rotateZ(-45deg);
  
  /* Styling */
  background-color: red;
  border-bottom: 5px solid #0c0c0c;
}
<div id="corner"></div>
Angel Politis
  • 10,955
  • 14
  • 48
  • 66
0

You can even try pseudo elements :before and :after.

#corner {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-top: 50px solid #000;
  border-bottom: 50px solid transparent;
  border-right: 50px solid transparent;
  border-left: 50px solid #000;
}
#corner:before{
  content:"";
  position:absolute;
  border-top: 5px solid red;
  border-left: 5px solid red;
  top:-50px;
  left:-50px;
  width:92px;
  height:92px;
}
#corner:after{
  content:"";
  position:absolute;
  border-right: 5px solid red;
  top:-104px;
  left:-83px;
  width:93px;
  height:140px;
  transform:rotate(45deg);
}
<div id="corner"></div>
frnt
  • 8,455
  • 2
  • 22
  • 25
  • user3550879 wanted the border **only** on the alngled side. –  Jul 30 '16 at 10:13
  • @IShad0wk I thought it needs to cover it's all corners border:red; – frnt Jul 30 '16 at 15:05
  • *"EDIT - I want it to have a 5px red border (only on the angled side) so the triangle and the border are different colors"* - user3550879. –  Jul 30 '16 at 23:56