P粉3916779212023-08-31 11:49:14
您需要將 :before
和 :after
新增到 .innertext
元素
更新:
要有多行,只需添加一個flex-direction: column
容器,每行都會有:after
(右)角,並且只有第一個子元素將有:before
(頂部)角
#outer { width: 100%; height: 400px; border-radius: 20px; background-image: url(https://media.istockphoto.com/id/1323032473/es/vector/panal-abstracto-de-vector-azul-moderno-con-fondo-de-monitor-de-coraz%C3%B3n-con-para-la.jpg?s=2048x2048&w=is&k=20&c=mXe4wSHc8kAcOXastbN9jhinrWGQX3vvJQUhDgvOcqA=); position: relative; } #inner-container { display: flex; flex-direction: column; align-items: flex-start; position: absolute; bottom: 0px; } .innertext { display: inline; position: relative; border-top-right-radius: 20px; background-color: #fff; padding: 5px 25px 0px 5px; font-size: 40px; color: #000; } .innertext:first-child::before, .innertext::after { content: ""; display: block; width: 40px; /* double the radius */ height: 40px; /* double the radius */ background-color: transparent; position: absolute; border-bottom-left-radius: 20px; box-shadow: 0 20px 0 0 #fff; /* this to create the inverted corner border radius area, if you desire to change the positon you can control it via the first two values 0 20px which represents the x & y */ } .innertext::before { top: -40px; left: 0; } .innertext::after { right: -40px; bottom: 0; } .innertext span { position: relative; z-index: 1; /* to overcome the overlapping with the text */ }
<div id="outer"> <div id="inner-container"> <div class="innertext"><span>A test</span></div> <div class="innertext"><span>A test with a second line</span></div> </div> </div>