Material design select with floating label

768 Views Asked by At

I need to add a floating label to this select menu. I found this framework https://tronic247.com/material/ and it seem to have a select component but no floating label, So how to add it / Thanks for any help.

<!DOCTYPE html>
<html>
<head>
    <title>My Material design Web Page</title>
    <meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width">
    <!-- CSS at head -->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
    <link href="https://res.cloudinary.com/tronic247/raw/upload/v1620900079/material.min.css" rel="stylesheet" />
    </head>
    <body>
        <div class="container p-5">
            <label for="rating">Choose a rating</label>
<select  class="filled">
    <optgroup label="Good">
        <option value="5">5+</option>
        <option value="10">10+</option>
        <option value="" disabled="">10+</option>
    </optgroup>
    <optgroup label="Bad">
        <option value="1">1</option>
        <option value="2">2</option>
    </optgroup>
</select>
        </div>
        <!-- JS at footer for optimized loading -->
        <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
        <script src="https://res.cloudinary.com/tronic247/raw/upload/v1620900084/material.min.js"></script>
    </body>
</html>

1

There are 1 best solutions below

0
Klaassiek On

As far as I can see from the documentation, the library you use does not have an option for floating labels. Try some other library that does have floating labels, like Material Design Lite or another that has built-in this option.

<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<!-- Textfield with Floating Label -->

<form action="#">
  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
    <input class="mdl-textfield__input" type="text" id="sample3">
    <label class="mdl-textfield__label" for="sample3">Text...</label>
  </div>
</form>
<!-- Numeric Textfield with Floating Label -->
<form action="#">
  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
    <input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="sample4">
    <label class="mdl-textfield__label" for="sample4">Number...</label>
    <span class="mdl-textfield__error">Input is not a number!</span>
  </div>
</form>