Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Triangle + "After" Implementation

Tags:

css

I have tried to create a triangle with CSS and it looks good, however I have now got a problem implementing it after a box.

Check out my example and you will see what I mean:

https://jsfiddle.net/TTVuS/

It seems like the triangle after .box gets "cut off" and I have absolutely no idea why this happens.

I want it to look like .arrow.

I have tried to change dimensions of the box, the triangle etc. but nothing worked.

p.s. here is the css in case Jsfiddle is slow or not available again:

.box{     background:red;     height:40px;     width:100px; }  /*the triangle but its being cut off*/ .box:after{     content:"";     width:0;     height:0;     border-top:20px solid transparent;     border-bottom:20px solid transparent;     border-left:20px solid green; }  /*the triangle how it should look like*/ .arrow{     width:0;     height:0;     border-top:20px solid transparent;     border-bottom:20px solid transparent;     border-left:20px solid green; } 
like image 831
r0skar Avatar asked Nov 30 '11 14:11

r0skar


People also ask

How do I insert a triangle symbol in CSS?

STEP 1 : Make a div You may use any techinque (see here) including the use of percentages and padding-bottom to maintain the aspect ratio and make a responsive triangle. In the following image, the div has a golden yellow border. In that div, insert a pseudo element and give it 100% width and height of parent.

How do CSS triangles work?

The idea is a box with zero width and height. The actual width and height of the arrow is determined by the width of the border. In an up arrow, for example, the bottom border is colored while the left and right are transparent, which forms the triangle.


1 Answers

Changing the triangle to position: absolute; and adding position: relative; to the .box fixes it. It seems to be inheriting the height of the box.

like image 192
Nate B Avatar answered Oct 04 '22 11:10

Nate B