I’m trying to create a red box (as shown in the picture) that has a notch on the top edge. This notch should have rounded corners with an inverted border radius. Then I wanted to write a word in the notch, with the size of the notch depending on the length of the word. There will also be text on the box later. Everything that is black in the picture should be transparent so that the background can be adjusted later.
I’ve already tried countless times. But either the background of the notch was not transparent, or the corners were not as rounded as in the picture. Another problem I encountered was that not everything was in a rectangular container, but some elements were outside.
2
Answers
You can use the
::before
pseudo element to achieve this. Here is an example:I think i got it by using a big div for the whole top notch area (black and red parts) which has a black background.
In there are 3 divs, a left and right part and the center actual notch area.
left and right have a red background, the notch area a red one.
left and right get a border radius on the border to the screen and the border for the inner border-radius and the notch in the notch-area gets a black background and a border radius for the bottom edges.
This only works with a plain background, not a more complex content. I bet there are some svg and clip path magic one can do but if you only use plain backgrounds and you dont need to display content below the header-area where the notch is this should work.
Also if we use a flex box for the whole notch-area and use space-between the width of the notch is dynamic