0

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/[email protected]/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/[email protected]/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.

1
  • I've updated code to bootstrap 3.2.0 and I thnik it's about bootstrap version. But i can not update to 5.3.0 :(
    – akikara
    Commented Sep 8, 2023 at 15:35

1 Answer 1

2

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/[email protected]/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/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

3
  • Thank you so much for all. At this time I can not update to bs5.
    – akikara
    Commented Sep 8, 2023 at 21:52
  • I've added oninput="this.nextElementSibling.value = this.value" parameter and after closing tag have an <outpt></output> before applyıng answer ıt was workıng. any help @siddharth-bhansali
    – akikara
    Commented Sep 8, 2023 at 22:11
  • It seems to work fine in the snippet. Though the min/max is 0-100. If you want those to be 22-222, you need to set that in the input itself. Refer: w3schools.com/tags/att_input_type_range.asp Commented Sep 9, 2023 at 6:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.