1

have tried the below code but my image didnt change to the triangle shape. Help me with some solutions for my problem

.triangle {
 border-left: 50px solid transparent;
 border-right: 50px solid transparent;
 border-bottom: 100px solid transparent;
}
4
  • you add only transparent border. Commented Mar 23, 2015 at 10:30
  • 1
    Looks like you're trying to do this: css-tricks.com/snippets/css/css-triangle If you're trying to clip an img into a triangle, this won't work Commented Mar 23, 2015 at 10:31
  • use absolute property or set width & height Commented Mar 23, 2015 at 10:31
  • more details please of what image you need to in that triangle :p Commented Mar 23, 2015 at 10:45

3 Answers 3

3

If you play about with the borders, and you have a solid color for a background, you could use something like:

div {
  height: 300px;
  width: 300px;
  position: relative;
  background: url(http://placekitten.com/g/300/300);
}
div:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 0%;
  border-bottom: 300px solid transparent;
  border-left: 150px solid white;
  border-right: 150px solid white;
}
<div></div>

Which is using a pseudo element to 'clip' the triangle shape

Sign up to request clarification or add additional context in comments.

Comments

1

If you're trying to clip an image into the shape of a rectangle, use clip-path.

Here's a nice helper: http://bennettfeely.com/clippy/

Comments

1

CSS:

.triangle {      
  width: 0; height: 0;
  border-bottom: 116px solid blue;
  border-left: 116px solid transparent;
  border-right: 116px solid transparent;
}

Fiddle url: http://jsfiddle.net/Khumesh/kpm1feLo/

Try this one: http://jsfiddle.net/Khumesh/zbh3ewLd/

1 Comment

I dont want the blue color instead want change to my image to a triangle shape.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.