1

Hello is it possible create a triangle with inverted rounded corner in the center of a rectangle, like in many landing page. Something like the below image:

enter image description here

I found something similar here but without inverted rounded corner CSS Inverted Triangle image overlay

1 Answer 1

5

Yes, it is possible to achieve this effect by using two pseudo-elements. We need to position one of the pseudo-elements with respect to the left of the container while other is positioned with respect to right of the container. Then by adding a transform: skew() on them in opposite directions and assigning a border-radius to the required sides we can get the required output.

div {
  position: relative;
  height: 50px;
  width: 100%;
  padding-top: 50px;
  background: blue;
  background-clip: content-box;
  /* make sure blue background doesn't appear behind triangle */
  overflow: hidden;
  color: white;
}
div:before,
div:after {
  position: absolute;
  content: '';
  top: 0;
  width: calc(50% + 10px);
  /* don't change */
  height: 50px;
  /* must be equal to padding-top */
  background: blue;
}
div:before {
  left: 0;
  transform: skew(45deg);
  transform-origin: right bottom;
  border-top-right-radius: 12px;
}
div:after {
  right: 0;
  transform: skew(-45deg);
  transform-origin: left bottom;
  border-top-left-radius: 12px;
}
<div class='shape'>This is a shape.</div>

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

7 Comments

wow thank u! It's possible add text in that div? i try here jsfiddle.net/nhqKb/284 the triangle is great, but the text doesnt shown
@Harry, Damn...fast as lightning XD
sorry i paste the wrong link was another arrow without rounded corner, i edit that 60 second later, u was faster :)
Hehehe but not as fast as Harry :p
@JoTaRo: Yes, it can be. Please check the updated answer.
|

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.