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.)
Even in pure CSS we can get the smooth diagonals.
Instead of giving transparent you can make use of rgba(255, 255, 255, 0). This again gives transparent. But the alpha=0 makes smooth diagonals.
Check the browser support for rgba css-tricks.com/rgba-browser-support
Thanks
For me, using
dashed
for the transparent borders worked for most browsers that don't automatically smooth them and rotating 360 degrees worked for old Webkit:I have just stumbled upon the same problem, and figured out this trick (at least, it works on a Mac):
A very hacky way would be using a rotated div
Here I used two divs to show a triangle:
and rotated the inner div for two not right sides of triangle:
I didn't tried to find the relation between numbers.
Here is the fiddle of the code:
http://jsfiddle.net/mohsen/HTMcF/
BUT I would strongly suggest you to use
canvas
element for this reason.None of the others worked for me, but I found the following did (by accident):
The mixture of dashed/solid and the rgba fix worked in FF31, IE11, and Chrome36.
For Firefox you can add -moz-transform: scale(.9999); to make smooth edges. In your case:
Will do the trick.