Looking to create a responsive design for the range slider below

How can I make this Range slider fully responsive? The text overlaps when viewed on a mobile device, and my attempts to add it to a responsive table or divs have not been successful. Can someone provide guidance on how to achieve responsiveness for this slider?

If you'd like to see the code snippet:

@import url(https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet);
@import url("https://fonts.googleapis.com/css?family=Dancing+Script");

  

.label-container {
  margin-top: 0.5rem;
  -webkit-flex-basis: 100%;
  display: -webkit-flex;
  -webkit-flex-wrap: nowrap;
  -webkit-justify-content: space-between;
  margin-bottom: 50px;
}

.label-slider {
  color: #3949ab;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.label-slider:nth-child(1) {
  padding-left: 0px;
}

.label-slider:nth-child(2) {
  padding-left: 18px;
}

.label-slider:nth-child(3) {
  padding-left: 34px;
}

.label-slider:nth-child(4) {
  padding-left: 32px;
}

.label-slider:nth-child(5) {
  padding-left: 32px;
}

.slider-container {
  width: 100%;
  margin-top: 5px;
}

.slider {
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  height: 10px;
  border-radius: 5px;
  background: #dde5ff;
  outline: none;
  opacity: 0.7;
  -webkit-transition: 0.2s;
  transition: opacity 0.2s;
}

input[type="range"],
input[type="range"]::-moz-range-track {
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  border-radius: 5px;
  background: #dde5ff;
  outline: none;
  transition: opacity 0.2s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #2b8aeb;
  cursor: pointer;
  outline: none;
}

input[type="range"]::-moz-range-thumb {
  -moz-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #1492ea;
  cursor: pointer;
  outline: none;
  z-index: 10;
}

input[type="range"]:focus {
  outline: none;
}

Answer №1

Replace the width: 600px with max-width:600px; in the container.

I suggest setting the font size based on rem units and adjusting breakpoints for font sizes on your html element to achieve the desired sizing. You can refer to this topic: Rem not compatible with media queries?

Additionally, consider removing padding from the container when the screen width is below a certain threshold to ensure proper alignment with your input.

Edit

To correctly position the container labels, make them absolute:

Firstly, add position:relative; to the container:

.label-container{
  position:relative;
}

Then, apply position: absolute; to the labels:

.label-slider{
  position: absolute;
}

Finally, adjust their positions using absolute positioning according to the following rules:

.label-slider:nth-child(1) {
  left:0;
}

.label-slider:nth-child(2) {
  left:25%;
  transform: translateX(-25%);
  margin-left: 1%;
}

.label-slider:nth-child(3) {
  left:50%;
  transform: translateX(-50%);
  margin-left: .5%;
}

.label-slider:nth-child(4) {
  right: 25%;
  transform: translateX(25%);
  margin-left: 1%;
}

.label-slider:nth-child(5) {
  right:0;
}

FULL DEMO

@import url(https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet);
@import url("https://fonts.googleapis.com/css?family=Dancing+Script");

body {
  font-family: "Catamaran", sans-serif;
  background: #2b8aeb;
}

.container {
  font-family: "Catamaran", sans-serif;
  max-width: 600px;
  margin: 30px auto 0;
  display: block;
  background: #fff;
  padding: 10px 50px 50px;
  border-radius: 4px;
  box-shadow 0 6px 16px rgba(0,0,0,0.15)
}

.title {
  text-align: center;
  font-family: "Dancing Script", cursive;
  color: #3949ab;
  font-size: 35px;
}

.label-container {
  margin-top: 0.5rem;
  -webkit-flex-basis: 100%;
  display: -webkit-flex;
  -webkit-flex-wrap: nowrap;
  -webkit-justify-content: space-between;
  margin-bottom: 50px;
  position : relative;
}

.label-slider {
  color: #3949ab;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  position: absolute;
}

.label-slider:nth-child(1) {
  left:0;
}

.label-slider:nth-child(2) {
  left:25%;
  transform: translateX(-25%);
  margin-left: 1%;
}

.label-slider:nth-child(3) {
  left:50%;
  transform: translateX(-50%);
  margin-left: .5%;
}

.label-slider:nth-child(4) {
  right: 25%;
  transform: translateX(25%);
  margin-left: 1%;
}

.label-slider:nth-child(5) {
  right:0;
}

.slider-container {
  width: 100%;
  margin-top: 5px;
}

.slider {
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  height: 10px;
  border-radius: 5px;
  background: #dde5ff;
  outline: none;
  opacity: 0.7;
  -webkit-transition: 0.2s;
  transition: opacity 0.2s;
}

input[type="range"],
input[type="range"]::-moz-range-track {
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  border-radius: 5px;
  background: #dde5ff;
  outline: none;
  transition: opacity 0.2s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #2b8aeb;
  cursor: pointer;
  outline: none;
}

input[type="range"]::-moz-range-thumb {
  -moz-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #1492ea;
  cursor: pointer;
  outline: none;
  z-index: 10;
}

input[type="range"]:focus {
  outline: none;
}

.ticks {
   font-family: "Catamaran", sans-serif;
  color: #3949ab;
  font-size: 14px;
  font-weight: 700;
    display: flex;
    justify-content: space-between;
    height: 6px;
    margin: 0 10px 0 15px;
    counter-reset: count -1;
}
.ticks > div {
  height: 100%;
  width: 1px;
  background: silver;
  counter-increment: count 1;
}
.ticks > div:nth-child(5n - 4) {
  height: 200%;
}
.ticks > div:nth-child(5n - 4)::before {
  display: block;
  content: counter(count,decimal);
  transform: translate(-50%, 100%);
  text-align: center;
  width: 16px;
}
<body>
  <div class="container">
    <p class="title">Range Sliders</p>

    <h4>Range Slider without steps</h4>
    <div class="slider-container">
      <input type="range" min="0" max="4" class="slider">
    </div>

    <div class="label-container">
      <div class="label-slider">None</div>
      <div class="label-slider">1</div>
      <div class="label-slider">2</div>
      <div class="label-slider">3</div>
      <div class="label-slider">4+</div>
    </div>

     

  </div>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing inappropriate HTML attributes

Imagine I have a different layout: <div> <p>My Laptop </p> <p>My Phone </p> </div> With jQuery, if one of these items is clicked, I want to display its value. Would it be acceptable to store extra information in an att ...

The conflict between Material UI's CSSBaseline and react-mentions is causing issues

Wondering why the CSSBaseline of Material UI is causing issues with the background color alignment of React-mentions and seeking a solution (https://www.npmjs.com/package/react-mentions) Check out this setup: https://codesandbox.io/s/frosty-wildflower-21w ...

Hide jquery scroll bar

I am currently working on a WordPress plugin with the Twenty Thirteen theme. My goal is to display a modal when a div is clicked, and at that time I want to hide the scrollbar on the body of the page. Despite trying the following code snippet, it doesn&ap ...

Manipulate the CSS of Quasar components within a child component in VueJS

Currently, I am incorporating Quasar components into my VueJS application in order to create an app. Within this setup, I have a child component that is being imported into a parent component. To customize the child component's appearance, I have over ...

Google Maps Geolocation does not prompt for authorization

I'm currently working on implementing the Google Maps API in one of my web pages, following the instructions provided at https://developers.google.com/maps/documentation/javascript/geolocation. What I've been doing is simply copying the code fro ...

Refresh the HTML content within a specified div element

In my index.html, there is a graph (created using d3.js) along with some code that displays a stepper with a number of steps equal to the child nodes of the clicked node: <div ng-include="ctrl.numlab==2 && 'views/stepper-two-labs.htm ...

Tips for designing a chosen radio button with interactive space:

After stumbling upon this CSS query regarding styling selected radio buttons labels from Stack Overflow and also checking out this discussion on UX Exchange, I attempted to apply both techniques but couldn't quite get it right. It seems that a parent ...

Ways to perform a force click on a span element when clicking on a glyphicon

There is a table cell containing two span elements: <span contentEditable=true class="editspan"></span> <span class="pencilspan glyphicon glyphicon-pencil pull-right"></span>" When clicking on span1, an input box appears for editi ...

Generating a Fresh HTML File with Selenium Using a ChromeWebElement

I am utilizing VB.net 2019 and Selenium to generate a fresh .htm file by extracting information from ChromeWebElement and adding necessary statements before and after. My attempt looks something like this:- Dim ele As OpenQA.Selenium.Remote.RemoteWebElemen ...

Change the color of specific elements in an SVG using React

Can I change the dynamic primary color from ReactJS to a specific class in an SVG file? If yes, how can it be done? Error.svg <!-- Generator: Adobe Illustrator 26.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <svg version="1.1&qu ...

The HTML navbar seems to have a mind of its own, disappearing and shifting around unpredictably as I zoom in or resize

WHEN DISPLAYING THIS CODE, IT IS ADVISED TO VIEW IN FULL PAGE MODE This code includes navigation, header, and styling elements. However, when the browser is zoomed in or out, the navbar tends to move around and eventually disappears off the screen if wind ...

Converting HTML to PDF with the Google Drive API

Can you transform an HTML file into a PDF using Google Drive API without needing any user input or interaction? ...

Vue Error: The function slugify is not defined

Currently, I am working on a feature where I want to extract the value from one input field, convert it into a slug format, and display it in another input field. This project involves Laravel Spark, Vue, and Bootstrap 4. Here is the content of my listing ...

Experience a seamless transition as the background gently fades in and out alongside the captivating text carousel

I have a concept that involves three background images transitioning in and out every 5 seconds. Additionally, I am utilizing the native bootstrap carousel feature to slide text in synchronization with the changing background images. Solving the Issue ...

Stylized search input inspired by Pinterest with a bubbly design

When it comes to my search bar, I want the user's entered keywords to be displayed within a bubble that has a delete option when they press space to add another keyword. This functionality is similar to what Pinterest does with their search bar, as de ...

The PHP form is failing to successfully submit due to a custom error message occurring

I'm having trouble with my PHP form submission. Every time I try to submit, I receive a custom error message that says "Oops there was a problem. Please try again." Any assistance would be greatly appreciated. As a newcomer to PHP, I suspect that som ...

Blend a background image using rgba without incorporating a gradient effect

Can you merge a background image with an rgba color without resorting to an rgba gradient? My current CSS3 style appears as follows: html { background: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)), url("../icons/sombrero.jpg")no-repe ...

Aligning divs containing images for the top navigation on my website

Struggling with coding for my top navigation bar. Check out my code here I'm working on placing social icons horizontally in my website's navigation bar but I've hit a roadblock. What is the most effective way to align these icons horizont ...

Creating a responsive design for embedding YouTube videos in web pages

I am facing an issue with embedding YouTube videos on my webpage. I have tried to make the videos responsive by using the code provided below, which works well on mobile and tablets. However, on desktops and laptops, the videos appear very large. As a work ...

Scrolling Horizontally, Tailored to Fit Content's Width

I am working with a page layout that consists of a wrapper, content div, and two item divs. The wrapper has a width of 320px, while the items together measure around 600px. I want the two item divs to display inline, allowing the content to scroll horizont ...