Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a CSS triangle with smooth edges?

I have a triangle (JSFiddle) using this CSS:

.triangle {     width: 0;     height: 0;     border-top: 0;     border-bottom: 30px solid #666699;     border-left: 20px solid transparent;      border-right: 20px solid transparent;     } 

And this HTML:

<div class="triangle"></div> 

This makes a triangle, but the diagonal lines are jagged and pixelated. How can I make them smooth? (I was able to smooth them out in Safari and Chrome by making them dotted, but that broke the triangles in Firefox and IE.)

like image 537
kirkaracha Avatar asked Sep 12 '11 22:09

kirkaracha


People also ask

How do you make a triangle with rounded corners in CSS?

Method 1.Use SVG's polygon tag <polygon> generate a triangle, and use SVG's stroke-linejoin="round" generate rounded corners at the connection. Here, it is actually the rounded corners generated stroke-linejoin: round attribute of the SVG polygon.

How do you draw a curved triangle in CSS?

triangle element and pointer-events: auto; on the pseudo-elements). Otherwise, this could be achieved by wrapping . triangle in an element having the same width and height (and the same border-radius ) and overflow: hidden; .


2 Answers

For Firefox you can add -moz-transform: scale(.9999); to make smooth edges. In your case:

.triangle {     width: 0;     height: 0;     border-top: 0;     border-bottom: 30px solid #666699;     border-left: 20px solid transparent;      border-right: 20px solid transparent;     -moz-transform: scale(.9999); } 

Will do the trick.

like image 106
Caner Şahin Avatar answered Oct 01 '22 01:10

Caner Şahin


I have just stumbled upon the same problem, and figured out this trick (at least, it works on a Mac):

-webkit-transform: rotate(0.05deg); -moz-transform: scale(1.1); -o-transform: rotate(0.05deg); /* Didn't check Opera yet */ transform: rotate(0.05deg); 
like image 29
unclenorton Avatar answered Oct 01 '22 02:10

unclenorton