вы можете попытаться сдвинуть текст вниз перед поворотом, учитывая его длину, используя способ вычисления вертикального отступа, когда используется процент.
вот несколько примеров: (см. Комментарий в css)
figure {position:relative;
overflow:hidden;}
figcaption {
position:absolute;
top:0;
padding:0.5em 3em 0.5em 2em;/* tune padding here*/
background:linear-gradient(to top, green 2.25em, transparent 2.25em);/* draw only one line average background*/
transform:rotate(-45deg);
transform-origin:bottom left;
box-sizing:border-box;/* include padding and border*/
min-width:150px;/* tune this to have a minimal width and way down*/
}
/* push me down */
figcaption:before {
content:'';
display:inline-block;
padding-top:90%/* 90% of my parent's width which i figcaption*/
}
<figure>
<img src="http://dummyimage.com/300x128">
<figcaption>caption </figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/300x128">
<figcaption>caption text</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/300x128">
<figcaption>longer caption text</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/300x128">
<figcaption>bit longer caption text</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/300x300">
<figcaption>tiny bit longer caption text</figcaption>
</figure>
Анимированная демонстрация, демонстрирующая эффект заполнения, для лент слева и справа
figure {
position: relative;
overflow: hidden;
display: inline-block;
margin:0;
}
.left figcaption {
position: absolute;
top: 0;
padding: 0.5em 3em 0.5em 2em;
/* tune padding here*/
background: linear-gradient( to top, green 2.2em, transparent 2.25em);
/* draw only one line average background*/
transform: rotate(-45deg);
transform-origin: bottom left;
box-sizing: border-box;
/* include padding and border*/
min-width: 150px;
/* tune this to have a minimal width and way down*/
/* animation for demo */
animation: txtin 2s steps(4) alternate infinite;
word-spacing: 2em;
color: white
}
/* push me down */
.left figcaption:before {
content: "";
display: inline-block;
padding-top: 94%;
/* 90% of my parent's width which i figcaption*/
}
.right figcaption {
position: absolute;
top: -3.5em;
right: -6em;
padding: 0.5em 4em;
/* tune padding here*/
background: green;
/* draw only one line average background*/
transform: rotate(45deg);
transform-origin: bottom left;
box-sizing: border-box;
/* include padding and border*/
min-width: 12.5em;
/* tune this to have a minimal width and way down*/
overflow: hidden;
/* demo */
animation: txtin 2s steps(4) alternate infinite;
word-spacing: 2em;
color: white
}
@keyframes txtin {
to {
text-indent: -21em;
color: yellow
}
}
<figure class="right">
<img src="http://dummyimage.com/300x300/0af/&text=right_ribbon_of_any_length">
<figcaption>ribbon animated demo</figcaption>
</figure>
<figure class="left">
<img src="http://dummyimage.com/300x300/0df/&text=left_ribbon_of_any_length">
<figcaption>ribbon animated demo</figcaption>
</figure>