I have img
and I want if the image can’t load, the alt appears in the middle of the image and if it’s too big it becomes an ellipsis
and it should be on one line
img {
width: 150px;
height: 75px;
background: #111;
display:flex;
align-items:center;
overflow:hidden;
text-overflow: ellipsis;
color:#fff;
white-space: nowrap;
}
<img src="" alt="Lorem ipsum dolor sit amet">
please no margin
, padding
or line-height
tricks i can’t use any of them because the img
height is 100%
i can’t know what is the final height
the code for firefox only so it must work in newest firefox version
2
Answers
You just need to add
display: inline-block
to your image and it will work.This won’t center the text though and won’t hide the broken image icon.
Use a pseudo element for this: