I'm in the process of updating a data-centric website that relies on information from an automated database engine. In the HTML, there's a fixed-size button containing text pulled from the database. I'm looking to incorporate some CSS styles to ensure the font always fits neatly within the button.
Below is the code snippet:
CSS:
.button {
width: 216px;
height: 44px;
background-color: 00baf2;
color: #fff;
border-radius: 5px;
font-size: 23px;
line-height: 45px;
font-weight: 500;
text-align: center;
@media screen and (max-width : 768px) {
.button {
width: 400px;
height: 81px;
font-size: 30px;
line-height: 40px;
background-size: 400px 81px !important;
float: none !important;
clear: both;
margin: 25px auto;
}
HTML
<div class="button">View Your Plan</div> (static/not data-driven)
<div class="button">Current Members Click Here</div> (data-driven)
<div class="button">Enroll Now</div> (static/not data-driven)
The second/middle button is data driven, with varying lengths between "Current Members Click Here" and "See Your Plan Discount Program Here". If I remove the font-size and line-height, it defaults to small text. How can I make sure the dynamic text always fits inside the div button, regardless of length? Is this achievable through CSS alone or would a JS solution be necessary?
Current layout: Desktop View https://i.sstatic.net/cXe1C.png Mobile View https://i.sstatic.net/nbDzJ.png
Desired outcome: Desktop https://i.sstatic.net/ROE67.png Mobile https://i.sstatic.net/6ygPI.png