Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making a Triangle using div #7

Open
niloy opened this issue Oct 1, 2013 · 0 comments
Open

Making a Triangle using div #7

niloy opened this issue Oct 1, 2013 · 0 comments

Comments

@niloy
Copy link
Owner

niloy commented Oct 1, 2013

Making a Triangle using div

I keep forgetting the technique, so writing it down here. This technique works
with borders.

This is how a box with 20px border will look like. Each border is given a
different color.

#box {
  border-left: 20px solid red;
  border-right: 20px solid blue;
  border-top: 20px solid black;
  border-bottom: 20px solid green;
  width: 20px;
  height: 20px;
}

border1

This is what happens when set the width and height of the box to zero.

#box {
  border-left: 20px solid red;
  border-right: 20px solid blue;
  border-top: 20px solid black;
  border-bottom: 20px solid green;
  width: 0;
  height: 0;
}

border2

We have 4 triangles. Now, its simply a matter of making a few of them
transparent, depending on the direction and the type of triangle we want.

If we make left and right borders transparent, and remove the top border,
we are left with a equilateral triangle pointing up.

#box {
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: none;
  border-bottom: 20px solid green;
  width: 0;
  height: 0;
}

border3

If we only make the top and right borders transparent, we have a right
angled triangle.

#box {
  border-left: 20px solid red;
  border-right: 20px solid transparent;
  border-top: 20px solid transparent;
  border-bottom: 20px solid green;
  width: 0;
  height: 0;
}

border4

Just make both of them the same colors, okay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant