Personalized Horizontal Radio Button Design

I have been struggling to achieve the desired design for radio buttons but without success.

https://i.sstatic.net/TU7Ks.png

Despite using bootstrap for my website, I am only able to achieve this:

https://i.sstatic.net/WbzqS.png

This is the code I am currently working with:

.content {background-color: #42d5b9; padding: 50px}

.amount-landing {text-align: center;}
.amount-landing label {color: #FFFFFF;}
.amount-landing > .col-xs-2 {background: url(https://i.imgur.com/K8Nz8Y2.png) repeat-x; background-position: 0 12px;}

.amount-landing input[type="radio"] {
    display:none;
}

.amount-landing input[type="radio"] + label span {
    display:inline-block;
    width:15px;
    height:15px;
    margin:0px 0px 0 0;
    vertical-align:middle;
    background: #FFFFFF;
    cursor:pointer;
    border-radius: 50%;
}

.amount-landing input[type="radio"]:checked + label span {
    background: #101B27;
}
         <div class="content "> 
          <div class="form-group">
            <div class="row amount-landing gray-line">
              <div class="col-xs-2 col-xs-offset-1"><input type="radio"><label for="amount1"><span></span></label></div>
              <div class="col-xs-2"><input type="radio"><label for="amount2"><span></span></label></div>
              <div class="col-xs-2"><input type="radio"><label for="amount3"><span></span></label></div>
              <div class="col-xs-2"><input type="radio"><label for="amount4"><span></span></label></div>
              <div class="col-xs-2"><input type="radio"><label for="amount5"><span></span></label></div>
            </div>
            <!-- This shows radio buttons -->


            <div class="row text-center" style="font-size: 14px;color: #FFFFFF;line-height: 14px;">
              <div class="col-xs-1"></div>
              <div class="col-xs-2">0$</div>
              <div class="col-xs-2">1$<br>-<br>1000$</div>
              <div class="col-xs-2">1001$<br>-<br>2001$</div>
              <div class="col-xs-2">2001$<br>-<br>3000$</div>
              <div class="col-xs-2">More than<br>3000$</div>
              <div class="col-xs-1"></div>
            </div>
            <!-- This shows numbers -->

          </div>
        </div>
        
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        

Basically, the code consists of columns with radio buttons and labels to create a custom radio button. I applied a gray line (an image) to all columns in the first row to show the background line, but this method covers all of the column backgrounds. In another row, I added amount labels, which also present responsive issues when the screen size is reduced and the labels get too close together.

Your help would be greatly appreciated to guide me in the right direction. Thank you.

Answer №1

To create radio buttons, use id and name attributes for the input type="radio". Radio buttons with the same name are considered as one group. Avoid using 'span' tags inside 'labels'.

The white background line can be styled using CSS pseudo element ":after" instead of background images. To prevent the background line from expanding beyond the last radio button, set the "content" property to none for the last div using the CSS pseudoclass ":last-of-type".

.content {background-color: #42d5b9; padding: 50px;}

.amount-landing {text-align: center;}
.amount-landing label {color: #FFFFFF;}
.amount-landing .amount-col {
position: relative;}
.amount-landing  .amount-col:after {
content: "";
position:absolute;
width: 100%;
height: 2px;
background-color: #fff;
top: 50%;
}
.amount-landing .amount-col:last-of-type:after {
content: none;
}
.amount-landing input[type="radio"] {
    display:none;
}

.amount-landing input[type="radio"] + label {
    display:inline-block;
    width: 20px;
    height:20px;
    margin:0px 0px 0 0;
    vertical-align:middle;
    background: #FFFFFF;
    cursor:pointer;
    border-radius: 50%;
}

.amount-landing input[type="radio"]:checked + label {
    background: #101B27;
}
<div class="content "> 
          <div class="form-group">
            <div class="row amount-landing gray-line">
              <div class="col-xs-2 col-xs-offset-1 amount-col"><input type="radio" id="amount1" name="amount"><label for="amount1"></label></div>
              <div class="col-xs-2 amount-col"><input type="radio" id="amount2" name="amount"><label for="amount2"></label></div>
              <div class="col-xs-2 amount-col"><input type="radio" id="amount3" name="amount"><label for="amount3"></label></div>
              <div class="col-xs-2 amount-col"><input type="radio" id="amount4" name="amount"><label for="amount4"></label></div>
              <div class="col-xs-2 amount-col"><input type="radio" id="amount5" name="amount"><label for="amount5"></label></div>
            </div>
            <!-- This shows radio buttons -->


            <div class="row text-center" style="font-size: 13px;color: #FFFFFF;line-height: 15px;">
              <div class="col-xs-1"></div>
              <div class="col-xs-2">0$</div>
              <div class="col-xs-2">1$-1000$</div>
              <div class="col-xs-2">1001$-2001$</div>
              <div class="col-xs-2">2001$-3000$</div>
              <div class="col-xs-2">More than 3000$</div>
              <div class="col-xs-1"></div>
            </div>
            <!-- This shows numbers -->

          </div>
        </div>
        
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

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

Sliding Navigation Panel

Currently, I am attempting to implement a sidebar push navigation that mimics the one showcased here. My HTML structure includes content within a center element div. The code snippet is as follows: <div id="mySidenav" class="sidenav"> <a href="j ...

What is the best way to include a secondary border to a responsive textarea?

Currently, I am utilizing Twitter Bootstrap 3.2.0 and below is the code snippet: Click here for jsFiddle .textarea textarea { background-color: white; background-image: url("http://ello.96.lt/images/as.jpg"); line-height: 1.56em; p ...

Bringing in typefaces to enhance your email signature

I am trying to design a unique email signature with a custom Adobe font. My email account is hosted by Strato, a German mail server. However, when I attempted to insert the signature using Apple Mail, I realized that the CSS <style> part was not bein ...

Determining the primary image in Galleriffic

After a recent inquiry, I am in the process of revamping a webpage to incorporate Galleriffic for optimized image loading, requiring me to delve deep into the intricacies of the task. I am encountering challenges in identifying the currently active image ...

Tips for eliminating the draggable item's shadow in Angular

Is there a way to remove the shadow seen under the backdrop when dragging an item in the Bootstrap modal dialog? In the image provided, I am trying to drag the "Personal Details" button..https://i.stack.imgur.com/uSNWD.png ...

Click to Rotate the Shape

I am attempting to apply a rotation effect on a shape when clicked using jQuery and CSS. My goal is to select the element with the id of x and toggle the class rotate on and off. The rotate class utilizes the CSS transform property to achieve the desired r ...

What is the best way to center my dropdown menu on the page?

Discover my exclusive menu by visiting this link. For those who are curious about the source code, here's the HTML snippet: <div id='menu-container'> <ul id='menu' class="menu"> <li class='active'>& ...

Dropping and dragging in the Dojo for the nested lists

Within my HTML code, I am using the Dojo drag and drop feature to sort attributes and move them to another section. However, I am having trouble figuring out how to sort the sections themselves. Here is the structure that I have created: <ul accept=" ...

Styling Your PHP Output with Echo

Is there a way to create a compact text box with a scroll bar that can display recurring data generated by PHP activities on the server side? How can I format it in this way? ...

Collecting all the <td> elements within a single row

I am having trouble creating a table dynamically using JSON data. The issue is that all <td> elements are being placed in the same <tr> instead of two separate rows. Here is my JavaScript code: $('button').click(function() { var str ...

upgrading the process of refreshing webpage

I am currently working on a basic chat application using PHP. The messages are being inserted into the database using AJAX, and the page is being refreshed every 5 seconds to display any new incoming messages. However, this method of refreshing the page co ...

Incorporate my personal design flair when utilizing third-party React.js component libraries

Incorporating Material UI as a component library in my React project has been beneficial. However, I am facing a challenge where the inline styling provided by Material UI clashes with my existing custom styles that I have developed over time. Is there a ...

Unable to transfer a value from a CGI script back to an HTML form

When working with an HTML form that has a date field named cdt, I encountered the need to retain the date value when submitting data to an Oracle table through a CGI script. To achieve this, instead of using Javascript code like history.go(-1), I aimed to ...

api for enhancing images in Laravel app through preview, enlarge, and zoom functionalities

As I work on my website, I aim to display images in a compact space, such as within a 300x300 <div>. What I envision is the ability for users to preview or enlarge these images upon clicking, allowing for a closer and more detailed view. For exampl ...

Execute button click automatically upon page loading in AngularJS

I'm trying to figure out how to automatically trigger a button click on an AngularJS page when the page loads based on a querystring value. In a traditional asp.net web forms page, I could easily handle this scenario by calling Button1_Click(sender,e) ...

Can someone explain why my table in Laravel is only showing the third set of data and not the others?

I'm facing an issue with displaying all of the data in my table named taglineImageCarousel. The problem lies in the slide_ID column, where it is being populated with data from slide-01, slide-02, and slide-03. Below is the code snippet: taglineImage ...

CSS and HTML modal not closing

I've been working on creating a custom popup using HTML, CSS, and some jQuery functions. My idea was that when I click on the main div, it should expand in size and display a cancel button, which it does successfully. However, the issue arises when tr ...

"I am facing an issue where the button does not appear centered after using jQuery

I can't help but notice that when applying CSS directly, my buttons end up centered horizontally. Yet, when I insert the same code using append(), the buttons seem to align towards one side instead. Here is the HTML/CSS code snippet: <div style=" ...

Creating a CSV download feature with ReactJS is simple and incredibly useful. Enable users

Despite searching through various posts on this topic, I have yet to find a solution that addresses my specific issue. I've experimented with different libraries and combinations of them in an attempt to achieve the desired outcome, but so far, I have ...

A guide to creating a personalized horizontal dashed separator in Material UI

I'm looking to customize a divider template by turning it into a horizontal dashed divider, but I'm struggling to override it. Even when attempting an sx edit with a borderRadius, the divider doesn't change as expected. source code: import ...