CSS unexpectedly altering a selected radio button choice

I am facing an issue with a 5-star rating system (radio buttons) that is intended to be used in two separate questions.

The problem arises when the ratings for each question seem to be linked, causing a selection made in one question to affect the other. This issue only occurs when I include the CSS code; without it, everything functions correctly.

I suspect that there might be something wrong in the CSS styling. Here is the snippet of the CSS code:

.estrelas input[type=radio] {
  display: none;
}

.estrelas label i.fa:before {
  content: '\f005';
  color: #FC0;
  font-size: 40px;
}

.estrelas input[type=radio]:checked~label i.fa:before {
  color: #CCC;
}

.estrelas {
  margin-left: 10px;
  margin-top: 10px;
}

And here is how the HTML structure looks like:

<div class="form-group has-feedback">
  <div class="col-xs-12">
    <label for="co_pergunta_avaliacao" class="control-label">ASPECTOS FORMAIS/GRAMATICAIS</label>
  </div>
  <div class="col-xs-8 estrelas" id="pergunta_1">
    <label for="cm_star-1"><i class="fa"></i></label>
    <input type="radio" id="cm_star-1" name="pergunta_1" value=1_1 />
    <label for="cm_star-2"><i class="fa"></i></label>
    <input type="radio" id="cm_star-2" name="pergunta_1" value=1_2 />
    <label for="cm_star-3"><i class="fa"></i></label>
    <input type="radio" id="cm_star-3" name="pergunta_1" value=1_3 />
    <label for="cm_star-4"><i class="fa"></i></label>
    <input type="radio" id="cm_star-4" name="pergunta_1" value=1_4 />
    <label for="cm_star-5"><i class="fa"></i></label>
    <input type="radio" id="cm_star-5" name="pergunta_1" value=1_5 />
  </div>
</div>

<div class="form-group has-feedback">
  <div class="col-xs-12">
    <label for="co_pergunta_avaliacao" class="control-label">CONTE&#218;DO/ARGUMENTA&#199;&#195;O</label>
  </div>
  <div class="col-xs-8 estrelas" id="pergunta_2">
    <label for="cm_star-1"><i class="fa"></i></label>
    <input type="radio" id="cm_star-1" name="pergunta_2" value=2_1 />
    <label for="cm_star-2"><i class="fa"></i></label>
    <input type="radio" id="cm_star-2" name="pergunta_2" value=2_2 />
    <label for="cm_star-3"><i class="fa"></i></label>
    <input type="radio" id="cm_star-3" name="pergunta_2" value=2_3 />
    <label for="cm_star-4"><i class="fa"></i></label>
    <input type="radio" id="cm_star-4" name="pergunta_2" value=2_4 />
    <label for="cm_star-5"><i class="fa"></i></label>
    <input type="radio" id="cm_star-5" name="pergunta_2" value=2_5 />
  </div>
</div>

Answer №1

It is essential for radio button IDs to be distinct from each other. The issue arises when the same IDs, such as cm_star-1 ... cm_star-5, are assigned to two radio buttons each.

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

Opting for HTML tags directly rather than using div.class

On my blogsite, I have implemented special tags that are designed to be user-friendly for my colleagues who may not be familiar with HTML. For instance: <question>...</question> and <answer>...</answer> These tags are then style ...

Achieve video lazy loading in JavaScript or jQuery without relying on any external plugins

I've been experimenting with lazy loading videos using jQuery. While I've had success with lazy loading images and background-images using the same technique, I ran into issues when trying to apply it to videos. Here's what I've tried s ...

Tips for managing the velocity of JavaScript navigation scrolling

Hey everyone, I recently discovered this incredibly helpful JavaScript sticky side navigation script and it works like a charm! However, since I don't know much about JS, I was wondering if there's a way to slow down the scrolling speed? functio ...

Adjust the height of the following column to match the responsive height of the initial column

Those who have marked it as duplicate, I want to clarify that my question is not about making Bootstrap columns all the same height. Instead, I am focusing on responsive images while maintaining their aspect ratio, which is a different issue from simply en ...

CSS translation animation fails to execute successfully if the parent element is visible

Inquiries similar to this and this have been explored, but do not provide a solution for this particular scenario. The objective is to smoothly slide a menu onto the screen using CSS translation when its parent is displayed. However, the current issue is ...

Is there a way for me to automatically update a webpage every 5 minutes, beginning at 8:01 a.m., and subsequently at 8:06 a.m., and so forth?

<html> <head>Harshal</head> <script> var limit="5:0" var doctitle = document.title var parselimit=limit.split(":") parselimit=parselimit[0]*60+parselimit[1]*1 function beginrefresh(){ if (parselimit==1) window.location.reload ...

Horizontal alignment of navigation bar items using <ul>

I'm trying to center the bar within the navigation bar vertically, but when I use align-items: center for the bar, it only centers the sign-in button, leaving it slightly above the middle position. nav a{ color:white; } nav{ justify-content: sp ...

White space in Bootstrap 4 grid caused by a full-width row

I have set up a bootstrap grid layout that includes ads, and I wanted to integrate a section for banners within it. After some experimentation, I managed to achieve this by inserting a container between the ads and the banners, each housed in their own row ...

Tips for eliminating the entire link from the footer section

Whenever a link is hovered over, a white box displaying the full URL appears at the bottom left of the browser. Is there a way to remove this feature from my website? I appreciate any assistance with this issue. Thank you! ...

What is the technique for filtering multiple values using the OR operation in ng-model functions?

Currently, I am using an ng-modal labeled as "myQuery." At the moment, there are two filters in place that look like this: <accordion-group heading="" ng-repeat="hungry_pets in Pets" | filter:{hungry:false} | filter:{name:myQuery}" ... > I have ...

Floating divs failing to clear properly in Internet Explorer

Encountered a persistent bug that only seems to occur in Internet Explorer. I have set up a jsFiddle to showcase the issue. <div class="container" style="width: 802px;"> <div class="block"></div> <div class="block"></div> ...

Having trouble pinpointing the issue with this particular if statement?

I am currently working on creating a form that compiles all entered data when the user fills out all fields. The form is connected to a PHP file and functions properly, but I encountered issues when implementing validation logic. The "Validation" section ...

Sorry, there was an issue: $controller:ctrlreg The controller you are trying to access is not registered

I'm currently watching a tutorial on AngularJS from safaribooks, following Lesson 3.1. Even though my code matches the one in the video, I'm encountering the error mentioned in the title. Below is my code: <html ng-app> <head> <l ...

Efficiently shrink column width in Material-UI's <TableRow/> using ReactJS and Material-UI

At the moment, I am utilizing ReactJS along with Material-UI. One issue I am encountering is that when using Material-UI's <Table>, the columns' width are automatically set based on content which results in all columns having equal width. H ...

When using the `position: absolute` and `left: 50%` properties on content with a `width: fit-content`, the content gets wrapped in Windows,

Why does the below code behave differently on Windows and Mac? On Windows, the content wraps or the div occupies only 50% of the browser's width, causing the content to wrap if its width exceeds 50% of the browser's width. However, on Mac, it tri ...

Utilize the pixels from a live video feed of a webcam through JavaScript, WebRTC, and MediaStreamTrack

My scientific project requires real-time processing of video streams from a webcam using JavaScript. Thanks to WebRTC, displaying live video on a website is easy, and <canvas> allows for capturing and processing screenshots. You can learn more about ...

Curved edges on a text box featuring a scroll bar

I'm facing an issue with my website where I have a large amount of text in an html textarea that requires a scroll bar. The problem is, I'd like to add rounded corners to the textarea, but it doesn't look good with the scroll bar. Below is ...

Two divs positioned on the left side and one div positioned on the right side

Hey there, I am attempting to align 2 divs on the left side with one div on the right. #div1 #div2 #div1 #div2 #div3 #div2 #div3 #div3 The challenge is to have #div2 positioned between #div1 and #div3 when the browser window is resized smaller. Currentl ...

Tips for adding data-mage-init to HTML elements

I have inserted the HTML content into a specific div. styleBasedProducts += "<div class='row image-full'><div class='col-md-12 home-title text-center'><div><span class='light'>Style Based</span>& ...

Accessing information from a database and showcasing it within a tooltip

I have successfully implemented a tooltip feature using JavaScript and integrated it into an HTML page. Check out the code snippet below: $(document).ready(function () { //Tooltips $(".tip_trigger").hover(function (e) { tip = $(this).find('.tip&a ...