Home > Back-end >  Word Wrapping in a button using Bootstrap 5
Word Wrapping in a button using Bootstrap 5

Time:08-04

I am trying to create a button using Bootstrap 5 which looks like this:

I went through this similar post, but couldn't find a solution.

This is the HTML code which I tried to write:

<button type="button" >
        <table>
          <tr>
            <td>
              <i ></i>
            </td>
            <td>
              <span style="font-size: 10px; margin-bottom:none;"> Download on the 
              </span><br>
              <span style="font-size: 15px; margin-top: none;"> App Store
              </span>
            </td>
          </tr>
        </table>
</button>
and this is the CSS:

.download-button {
    margin: 5% 3% 5% 0;
    white-space: normal !important;
    word-break: normal;
    word-wrap: break-word;
}

This is the output that I get:

Whose height is much more than required, and there's so much gap in the first and second line.

Any help would be appreciated!

CodePudding user response:

I will suggest that you use flexbox. I hope that this snippet can help. But please read up on flexbox for bootstrap https://getbootstrap.com/docs/4.0/utilities/flex

You can play around with the icons and text sizes yourself :)

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" async defer></script>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" async defer></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
    <button type="button" >
        <div style="gap: 5px" >
            <div >
                <i ></i>
            </div>
            <div style="line-height:1" >
                <span style="font-size: 10px; margin-bottom:none;"> Download on the
                </span>
                <span style="font-size: 15px; margin-top: none;"> App Store
                </span>
            </div>
        </div>
    </button>
</body>

</html>

  • Related