I have an h1 element that changes its HTML dynamically and I want it to auto shrink itself for longer text but return to its fixed font size for shorter text.
Here is the markup:
<div class="frame" dir="ltr">
<div class="frame-view">
<h1> //dynamic text </h1>
</div>
</div>
and the styling:
.frame {
z-index: 2;
position: relative;
top: 100px;
}
.frame-view {
text-align: center;
}
.frame-view h1 {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-style: normal;
font-variant: normal;
font-weight: 200;
font-size: 40px;
color: white;
padding: 0 20px;
}
Here's what the h1 looks like when a long text is in it, on a mobile screen:
rather than staying within the 20px
left, right padding and just auto shrinking the text, it stretches past the HTML.
in landscape it looks fine of course because there is enough room to contain it:
So how do I make this h1 auto shrink for longer text and stay within the boundaries ?
UPDATE
to further understand what I am trying to achieve, think of it like this:
I want the container of the h1 to be static and the text adjust its size when it gets closer to the container edges. Imagine a Label being 50 px, now if you put the word "hello" in that label at 20px font size, it would be 20px font size with no problem.. but if you put the words "Hello how are you" it wouldnt fit within the boundaries at 20px font size so it would have to auto shrink itself to stay within the boundaries of the container.