What is the best way to place a horizontal line behind buttons in a design?

Hello, I was experimenting with creating a background line behind the buttons on my webpage. Previously, I used an image for this purpose but now I want to achieve the same effect using a line.

<div class="feedback-option">
  <div class="radios2">
    <label>
      <input type="radio" name="rating-1" value="1">
      <span>1</span>
    </label>
    <label>
      <input type="radio" name="rating-1" value="2" />
      <span>2</span>
    </label>
    <label>
      <input type="radio" name="rating-1" value="3">
      <span>3</span>
    </label>
    <label>
      <input type="radio" name="rating-1" value="4">
      <span>4</span>
    </label>
    <label>
      <input type="radio" name="rating-1" value="5">
      <span>5</span>
    </label>
  </div>
</div>

Take a look at the JsFiddle here

Answer №1

To create a line in HTML, I utilized an empty div with specified background-color and height, positioned absolutely to the desired location.

.line {
  position: absolute;
  top: 25px;
  height: 5px;
  width: 100%;
  background-color: black;
}

Note: To center the radios, I updated the display: block; for .radios2.

.radios2 {
  display: block;
  text-align: center;
}

.line {
  position: absolute;
  top: 25px;
  height: 5px;
  width: 100%;
  background-color: black;
}

.radios2 label + label {
    margin-left: 10px;
}

.radios2 input[type="radio"] {
    opacity: 0;
    position: absolute;
}

.radios2 input[type="radio"] + span {
    display: block;
    line-height: 40px;
    height: 40px;
    width: 40px;
    border-radius: 50%;
    background: #eee;
    color: #555;
    -webkit-transform: scale(1);
    transform: scale(1);
}

.radios2 input[type="radio"]:not(:checked) + span:hover {
    cursor: pointer;
    -webkit-transform: scale(1.25);
    transform: scale(1.25);
    -webkit-transition: -webkit-transform 0.2s ease-in;
    transition: -webkit-transform 0.2s ease-in;
    transition: transform 0.2s ease-in;
    transition: transform 0.2s ease-in, -webkit-transform 0.2s ease-in;
}

.radios2 input[type="radio"]:checked + span {
    color: #D9E7FD;
    background-color: #4285F4;
}

.radios2 input[type="radio"]:focus + span {
    color: #fff;
}

label {
  display: inline-block;
}
<div class="feedback-option">
<div class="line"></div>
  <div class="radios2">
    <label>
      <input type="radio" name="rating-1" value="1">
      <span>1</span>
    </label>
    <label>
      <input type="radio" name="rating-1" value="2" />
      <span>2</span>
    </label>
    <label>
      <input type="radio" name="rating-1" value="3">
      <span>3</span>
    </label>
    <label>
      <input type="radio" name="rating-1" value="4">
      <span>4</span>
    </label>
    <label>
      <input type="radio" name="rating-1" value="5">
      <span>5</span>
    </label>
  </div>
</div>

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

Identifying when a system window covers an iframe

After watching a fascinating YouTube video (https://www.youtube.com/watch?v=TzPq5_kCfow), I became intrigued by how certain features demonstrated in the video could be implemented using JavaScript. One specific question that arose for me was how one can d ...

The primary container is brimming with an abundance of content

Can anyone help me with a CSS issue I'm experiencing in the latest versions of Chrome and Firefox? I can't seem to figure it out on my own. The problem arises with a container div that has a 50px top margin. Inside this container, there's a ...

The tooltip feature for icon buttons within Material UI list items is not functioning properly as anticipated

Just starting out with Material UI and React, I've encountered a strange UI problem that I can't quite figure out. Hopefully someone here can help me identify what I did wrong. My Approach: I have a List in my code where each list item has butto ...

How to Customize the Placeholder Text of a TextField

When working with the TextField API, I noticed that there is no mention of how to style the pseudo placeholder element of the input element. I want to customize the default styling of the placeholder text, but the usual CSS tricks don't seem to work ...

Tips for Integrating a Facebook Shop Page into Your Website

Can a Facebook shop page be integrated into a website? Any guidance on how to accomplish this task would be greatly valued. ...

Exploring the functionalities of radio buttons and arrays in a Javascript experiment

Currently delving into the world of Javascript and struggling to wrap my head around creating a test using only pure Javascript (no jQuery). The goal is to: Present users with a question and provide radio button options for selection. Allow users to cho ...

Error message: Unhandled error - $(...).sidr does not exist as a function. [Chrome developer console]

I included this code in the basic module HTML block of a WordPress page builder and encountered the white screen of death. According to the Chrome developer console, the following error occurred: helpers.js?ver=4.5.3:15 Uncaught TypeError: $(...).sidr is ...

Take a snapshot of an element using fixed element positioning

When it comes to extracting a sub image from a webpage using Selenium, I have found a reliable method. First, I capture a screenshot of the entire page and then extract the desired sub-image using the element's coordinates. Dimension elementDimension ...

The Asp button fails to initiate the function

One area of concern I have is with the signup page for my project, particularly regarding the following code: <input type="email" id="email" title="invalid email!" runat="server" placeholder="email" /> ...

Having difficulty reaching a div element using either its id or class in a CSS stylesheet

I'm having trouble adding padding to the home section div and I can't seem to access it using either the id or class. Any suggestions on how to solve this issue would be greatly appreciated. Below is the CSS code: body { margin: 0 ; font ...

Manipulating the location where a dropdown menu intersects with a button

Is there a way to adjust the drop-down menu positioning so that it aligns with the button on the top right side of the menu pop-up, rather than the top left as it currently does? Below is the code I have borrowed from an example on W3Schools. .dropbtn ...

Design featuring a combination of vertical columns and a fixed image placed in

I'm currently in the process of creating a website and I have a specific page layout in mind that I would like to implement: ------------------------------------------ | A catchy title | | | Here | An unconve ...

Preventing links from functioning on dynamically generated web pages

I have implemented the following code to deactivate all links on a preview page: var disableLink = function(){ return false;}; $('a').bind('click', disableLink); While this successfully disables all static links, any anchor tags loade ...

Tips for successfully passing a Prop using the Emotion CSS function

Passing props through styled() in Emotion is something I'm familiar with. For example: const Container = styled("div")<{ position: string }>` display: flex; flex-direction: ${({ position }) => (position === "top" ? "column" : "row ...

Having trouble accessing an element using jQuery(idOfElement) with a variable as the name parameter

Possible Duplicate: Issue with JavaScript accessing JSF component using ID Whenever I attempt to retrieve an element by passing a variable in jQuery(idOfElement), it doesn't work. But if I use something like jQuery('#e'), it works perfe ...

Using target="_blank" is necessary for iOS tel: and mailto: links to function properly

Although this question has been circulating widely, I have yet to come across a global solution that fits my needs. Here is the HTML snippet in question: <div class="contact-details__content-container"> <h4 class="contact-details__title">Pr ...

Incorporating fresh components and newly defined attributes in Angular

Is there a way for me to click on a new component button, specify a name, description, select type, and add attributes such as default value and type? I need all this information to be saved and for the new button to appear in the drag-and-drop section. ...

Navigational elements, drawers, and flexible designs in Material-UI

I'm working on implementing a rechart in a component, but I've encountered an issue related to a flex tag. This is causing some problems as I don't have enough knowledge about CSS to find a workaround. In my nav style, I have display: flex, ...

Using Jquery to select and apply functions to specified div elements

As someone who is relatively new to JQuery, I have a question regarding the .on() function. Take this example: $('div').on('click', function() {$(this).toggleClass('show-description');}); This code selects all the 'div& ...

Adjust the size of an HTML image for printing using a JavaScript window.print() function

On my website, I have a print option set up where specific elements are hidden using @media. How can I adjust the size of an image within the @media query when my JavaScript print function is triggered? I am able to modify a regular div element easily, but ...