Changing the appearance of a label upon checking an input is unsuccessful

Encountering an issue with modifying labels associated with a specific input. While changing a subsequent div upon checking the appropriate input (checkbox) works seamlessly, attempting the same approach for labels yields failure results. Even wrapping a label in an additional div and trying to target that instead of the label itself does not produce any desired outcome.

The main question here is: What am I missing or doing wrong in this scenario?

HTML

<input type="radio" id="TabOne" class="sheet-TabOne" name="Tab" checked="checked" />
<input type="radio" id="TabTwo" class="sheet-TabTwo" name="Tab" />

<div class="sheet-TabHeader">
    <label for="TabOne" class="sheet-TabOne">One</label>
    <label for="TabTwo" class="sheet-TabTwo">Two</label>
</div>


<div class="sheet-TabContent sheet-TabOne">
    First content
</div>

<div class="sheet-TabContent sheet-TabTwo">
    Second content
</div>

CSS:

label.sheet-TabHeader {
    float: left;
    width: auto;
    border: 2px solid #A52A2A;
    width: 150px;
    height: 20px;
    font-size: 18px;
    background: #fff;
    color: black;    
}

input.sheet-TabOne:checked ~ label.sheet-TabOne, 
input.sheet-TabTwo:checked ~ label.sheet-TabTwo
{
    background: black;
    color: red
    text-shadow: 0px 0px 5px black,0px 0px 5px black,0px 0px 5px black;
}

div.sheet-TabContent {
    display: none;   
    clear: left;
}

input.sheet-TabOne,
input.sheet-TabTwo
{
    display: none;   
}

input.sheet-TabOne:checked ~ div.sheet-TabOne, 
input.sheet-TabTwo:checked ~ div.sheet-TabTwo
{
    display: block;   
}

Answer №1

From my understanding, the label tag is specifically for use with the input tag. It cannot be used with a div tag, as it is meant to link to the input's id. In this case, you are attempting to connect them to a div that does not have an id.

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

Guide to setting up a nested vuetify navigation drawer

I am facing a scenario where I have one fixed navigation drawer with icons and another dynamic navigation drawer that should open and close adjacent to the fixed one without overlapping. The current implementation is causing the dynamic drawer to overlap t ...

What is the reason behind receiving a CSS warning stating "Expected color but found '0' " when using Phaser's setText() function?

Here's how I created my text object: statusBarHP.text = game.add.text(0, 0, '', { font:"16px Arial", fill:"#ffffff", stroke:"#000000", strokeThickness:2 }); For the object that holds the text: statusBarHP = game.add.sprite ...

Tips for accessing the target of a function call within Vue.js when it's within the {{ }} notation

Is it possible to use the $event notation with v-on in order to manipulate the source of the event, like in this example: <button @click="test($event.target)">Big red button, don't push it</button> I'm wondering if I can a ...

Can a single SVG file be referenced and reused multiple times in a project?

Instead of repeating these code blocks: <svg class="icon-user"> <use href="LONGFILENAME.svg#icon-user"> </use> </svg> <svg class="icon-user2"> <use href="LONGFILENAME.svg#icon-user2"> </use> </ ...

Activating the Speech Recognition feature in a form triggers the submission of a post

Currently, I am integrating webkitspeechRecongition into a form to allow users to enter data using their voice by pressing a button. However, a challenge arises when the call is triggered by a button within the form as it results in a post/submit action th ...

What is the importance of aligning spacing with the font size?

Currently, I am in the process of setting the margin spaces for elements within a webpage. In my review of the Bootstrap V4.0 documentation, I stumbled upon the fact that spacing is determined by the value $spacer, with $spacer defaulting to 1 rem. This l ...

The Boostrap card-deck appears to be see-through and malfunctioning

This problem has been puzzling me for quite some time now, and I just can't seem to find the solution! Kindly disregard the other language and code - the card is located under the jumbotron. (To access the link, remove spaces: https://code pen.io/ano ...

Experience the full functionality of Google Maps API without the need for jQuery or PHP with PanTo

I'm not a developer and I find myself stuck in the panTo() function. All I want is to execute this function with an if-else statement without having to reload the Google Map or using jQuery. <body> <div id="map"></div> <d ...

The react transition group fails to add the necessary CSS classes to the specified div

Regardless of whether I utilize React transition group, Tailwind, pure CSS, or any other framework, no transitions seem to occur when I structure my simple component in the following manner. I have experimented with various frameworks, but the outcome rema ...

How can I prevent Javascript click events from cascading, or ensure proper assignment to multiple divs in my code?

My goal is to create a single-page website where different sections are revealed or hidden based on navigation button clicks. However, I'm encountering issues with certain buttons not working unless the first button is clicked. Additionally, there&apo ...

Discover automatically generated titles for dynamic hyperlinks

I am looking to generate dynamic links for a collection of documents with varying names, such as Test, Test2, and so on. I want the link text to display as "Document TestN," where N is the specific document number. Currently, I am able to create the links ...

Utilize dynamic CSS application within an Angular application

In my Angular application, I dynamically load URLs inside an iframe and want to apply custom.css to the loaded URL once it's inside the iframe. I attempted using ng-init with angular-css-injector function in the iframe, but the CSS is not being applie ...

Could it be that v-show does not function properly on elements that are not dynamic

I'm not experienced in web development and this is my first attempt at using a web framework. The framework I am currently learning is vue.js version 3. My goal: I want to create 4 app instances (nav, defaultApp, bootstrapApp, vueApp). When I select ...

Retrieve information from an external JSON file and present it in a table format - Obtain the most recent data available

I am attempting to extract the data from On the website, there is a dropdown menu that displays two different screenshots. I want to modify my code so that it shows the most recent screenshot data in a table. Here is my current code: http://jsfiddle.net ...

Steps for retrieving the currently selected text inside a scrolled DIV

An imperfect DIV with text that requires a scroll bar For example: <div id="text" style='overflow:scroll;width:200px;height:200px'> <div style='font-size:64px;'>BIG TEXT</div> Lorem Ipsum is simply dummy text of th ...

Effortlessly apply CSS styles to multiple cached jQuery variables without redundancy

Hey there, I've got this piece of code written in Javascript for a classic ASP page. Since there are no CSS classes defined, everything is handled within the Javascript itself. var $a= $('#a'), $v= $('#v'), $s= $('#s'), ...

Enhancing Xcode security login through personalized security question prompts

I have been working on implementing the following code snippet: NSURL *url = [NSURL URLWithString:@"https://login.XXX.com/security/xxxforms// logonchalnp.fcc?TYPE=33554433&REALMOID=06-95b0f0c8-198a-1039-b583 83b02659fd47&GUID=&SMAUTHREASON=0&a ...

Choose checkboxes based on the checkboxes that were previously selected

My goal is to have a checkbox automatically selected based on the previously selected checkbox. For example, if I select the first checkbox (which has a specific class), then only the checkbox with the same class as the first one should be selected using j ...

Centered at the bottom of the screen lies a Bootstrap button

As a beginner with bootstrap, I am currently exploring new concepts and experimenting with different features. One thing I am attempting is to center a bootstrap button at the bottom of the screen. Here is my current code: .bottom-center { position: a ...

Is there a way to prevent a web page from automatically refreshing using JavaScript?

I would like my webpage to automatically refresh at regular intervals. However, if a user remains inactive for more than 5 minutes, I want the refreshing to stop. There is an example of this on http://codepen.io/tetonhiker/pen/gLeRmw. Currently, the page ...