twitter-bootstraptwitter-bootstrap-3

How to show bootstrap range's min max value before and after range slider?


I'm using classical bootsrtap css to make a range. I'd like to show the min and max value as pointed in the picture above.

Just as a text explanation

[min value] [range bar/slider] [max value]

as a straight line.

But my code shows three lines as

[min value]

[range bar/slider]

[max value]

Codes:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Bootstrap Range Input Example</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.2.0/dist/css/bootstrap.min.css">
</head>
<body>
  <div class="container">
    <form>
      <div class="form-group">
        <label for="rangeInput">Range Input</label>
       22 <input type="range" value="30" id="rangeInput" oninput="this.nextElementSibling.value = this.value"> 222
       <output>30</output>
      </div>
    </form>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.2.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Thank you for your help.

Bootstrap range min max value

Edit: Thank you for an answer. But I've added to show current value. But can not make it work.


Solution

  • You could use a flex box for it. Unfortunately I don't think Bootstrap 3.2 has in-built classes for that (please correct me if I am wrong), so you'd have to do with style tags, but works the same in the end.

    Your code becomes:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Bootstrap Range Input Example</title>
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.2.0/dist/css/bootstrap.min.css">
    </head>
    <body>
      <div class="container">
        <form>
          <div class="form-group">
            <label for="rangeInput">Range Input</label>
           <div style="display: flex; gap: 4px; align-items: center;">
           <span>22</span><input type="range" id="rangeInput"><span>222</span>
           </div>
          </div>
        </form>
      </div>
    
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.2.0/dist/js/bootstrap.bundle.min.js"></script>
    </body>
    </html>