我需要用HTML復(fù)制你在這張圖片中看到的內(nèi)容:
問題是文本用背景圖像覆蓋了一個div。如果在外部的div中沒有圖像和純色,我可以想象我可以很容易地用一些小的html元素在正確的位置放置圓角,但是背景圖像增加了復(fù)雜性。
到目前為止,我有這個...如你所見,我被困在兩個圓角上。有人能提出解決辦法嗎?:
#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;
}
#innertext {
display:inline;
border-top-right-radius:20px;
background-color:#fff;
padding:5px 25px 0px 5px;
font-size:40px;
color:#000;
position:absolute;
bottom:0px;
}
<div id="outer">
<div id="innertext">A test title<br>that is on two lines</div>
</div>
# # #我將重復(fù)使用我在以前的答案中使用的相同的想法,我考慮和SVG過濾器來創(chuàng)建圓角。
#outer {
height: 300px;
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;
overflow: hidden;
}
/* place the div at the bottom left */
#innertext {
font-size: 40px;
position: absolute;
z-index: 0;
bottom: 5px;
left: 5px;
filter: url('#round'); /* apply the filter to round the corners*/
}
/* use an inline element inside */
#innertext > span {
background-color: #fff;
padding: 5px 10px;
/* make sure the padding apply to all the lines */
-webkit-box-decoration-break: clone;
box-decoration-break: clone;
}
/* add two lines on the left and the bottom to complete the puzzle */
#innertext:before,
#innertext:after {
content:"";
position: absolute;
z-index: -1;
background: #fff;
left:-10px;
bottom: -10px;
}
/* vertical line */
#innertext:before {
height: 999px; /* very big value */
width: 20px;
}
/* horizontal line */
#innertext:after {
width: 999px; /* very big value */
height: 20px;
}
<div id="outer">
<div id="innertext"><span>A test title<br>that is on two lines</span></div>
</div>
<!-- the SVG filter -->
<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="round">
<feGaussianBlur in="SourceGraphic" stdDeviation="8" result="blur" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -8" result="goo" />
<feComposite in="SourceGraphic" in2="goo" operator="atop"/>
</filter>
</defs>
</svg>
# # #您需要向添加: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>