I have a list in an angular-app where each item can either contain a small image (as a div's background -> red) and some text or only text.
li {
display: flex;
border: 1px solid black;
width: 80%;
margin-bottom: 5%;
list-style: none;
position: relative;
}
.text {
text-align: center;
width: 100%;
background: lightgrey;
}
.image {
background: red;
width: 25%;
height: 100%;
position: absolute;
}
<ul>
<li><div class="text"><p>item 1<br/>some text</p></div>
</li>
<li><div class="image"></div><div class="text split"><p>item 2<br/>some text</p></div>
</li>
<li><div class="image"></div><div class="text split"><p>item 2<br/>some more text in a very very long line which may break at the end</p></div>
</li>
</ul>
Is there's an image with some text the center of the div containing the text will move. So both texts won't be one above the other. Is there any way to "center" the text of item2 to the li-element so that is consistent to its predecessor (preferably without javascript)?
EDIT: Using position: absolute
seems to work. But if the text is long enough it won't be broken (as favored) but it will disappear behind the red div or is shown in front of it. Since the red div will actually be filled by an image, floating text over it wouldn't be a good decision...
Of course I could calculate the width each item's text and break the lines manually but I would prefer an easier way.
To be specific, I want the text to be centered to the list-item (but not to the text-div) while it's lines are broken like in a div with 'width: 75%'.
Does anyone have some more hints?
Thanks