Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create Hollow triangle in css [duplicate]

Tags:

css

css-shapes

I want create hollow triangle with CSS but I don't how to hollow that. I can create triangle with CSS but I have one problem and this is: I can't hollow this triangle.

This is my code:

HTML:

<div id="tringle"></div>

CSS:

#tringle {
  position: absolute;
  height: 0;
  width: 0;
  top: 50%;
  left: 7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid white;
}
like image 777
julia Avatar asked Sep 04 '13 05:09

julia


People also ask

How do you add a triangle in CSS?

Normally there is no direct technique to create a triangle using CSS. Approach: To create the triangle, in the HTML part we have to just add a single div for each triangle. The concept is to create a box with no width or height. The width of the border determines the Triangle's actual width and height.

How do you make a shadow triangle in CSS?

Assuming we're cool with CSS3, one method would be to have a container box with hidden overflow and another box inside it which is rotate and hangs out of it. The part that is still visible would form a triangle. Then you can use a box-shadow on both the boxes to achieve a shadow all the way around.

Can you make shapes in CSS?

In this article, we will design some different types of shapes using CSS. CSS is capable of making all types of shapes.


2 Answers

Not exactly cross-browser but works. Hope I've understood your request.

http://jsfiddle.net/wmDNr/3/

 .triangle { 
     position: relative;
     width: 20px;
     margin-top: 100px;
 }
 .triangle>div { 
     width: 20px;
     height: 2px;
     background: red;
     margin-top: 100px;
 }

 .triangle>div:before {
     content: " ";
     display: block;
     width: 20px;
     height: 2px;
     background: red;
     -webkit-transform: rotate(56deg);
     -moz-transform: rotate(56deg);
     -ms-transform: rotate(56deg);
     transform: rotate(56deg);
     position: absolute;
     top: -8px;
     right: -5px;
 }
 .triangle>div:after {
     content: " ";
     display: block;
     width: 20px;
     height: 2px;
     background: red;
     -webkit-transform: rotate(-56deg);
     -moz-transform: rotate(-56deg);
     -ms-transform: rotate(-56deg);
     transform: rotate(-56deg);
     position: absolute;
     top: -8px;
     left: -5px;
 }
like image 57
Fez Vrasta Avatar answered Oct 23 '22 17:10

Fez Vrasta


I don't have solution but i have workaround with two triangle, FIDDLE

HTML CODE

<div id="tringle"></div>
<div id="tringle2"></div>

CSS CODE

    #tringle {
        left:10px;
        width: 0; 
        height: 0; 
        border-left: 100px solid transparent;
        border-right: 100px solid transparent;
        border-bottom: 100px solid black;
    }
    #tringle2 {

        left:10px;
        width: 0; 
        height: 0; 
        border-left: 50px solid transparent;
        border-right: 50px solid transparent;
        border-bottom: 50px solid #FFF;
        left: 57px;
        position: absolute;
        top: 38px;

    }
like image 42
rajesh kakawat Avatar answered Oct 23 '22 18:10

rajesh kakawat