I have the following code:
html:
<div class="outer">
<div class="inner">
some very very very very very very long text
</div>
</div>
css:
outer{
position:absolute;
width:100%;
height:40%;
background: rgba(0,0,0,.5);
}
.inner{
position:absolute;
bottom:10%;
left:50%;
max-width:100%;
transform: translate(-50%, 0%);
background: rgba(0,0,0,.5);
}
I want the text to be kept on one line as long as there is enough space in the outer div. But if the isn't enough space, then the shall be displayed on 2 lines.
I also need:
- the text to be centered,
- to be able to position the text vertically (bottom:10%;)
- the background of the inner div to be around the text, not on the full line
In the above code, there is available space when the text starts to be displayed on 2 lines.
I have tried white-space nowrap
, but it never goes on 2 lines...
Here is the jsfiddle: https://jsfiddle.net/yqvtgdhp/2/
The problem happens when the outer div becomes too narrow: try to decrease its width by resizing the browser's window for example.