I am having a h3
, which may have long or sometimes short text. I have manually set the font-size
of the h3
to 3rem
. But when it is a long text, the text starts to overflow the parent div. When it is a short text, it appears to be small (font-size). How can I make the h3
's font-size
to automatically scale according to the parent div? Note that the parent div has a fixed height and width and has nothing to do with the screen size.
<div id="book_div">
<div className="book-div_container">
<p className="book-div_author">{author}</p>
<div className="book_div_data">
{series && <h2 className="book_div_series">{series}</h2>}
<h3 id="bookdivtitle" className="book_div_title">
{title}
</h3>
</div>
</div>
</div>
#book_div {
height: 18.875rem;
width: 12.25rem;
background-color: #857073;
color: white;
font-family: "Noto Sans JP", sans-serif;
padding: 1rem;
box-shadow: 0 0 10px grey;
}
.book-div_container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.book-div_author {
font-size: 100%;
}
.book_div_data {
padding-top: 3rem;
}
.book_div_series {
font-size: 1.5rem;
text-align: center;
}
.book_div_title {
text-align: center;
word-break: break-all;
}
Edit: CodeSandbox link is here.
Any help is greatly appreciated !
Thanks!