Avatar of kgp43
kgp43
Flag for Denmark asked on

Change label background color on radio select

Hi,

I have this html code:
<label for="y1" class="radio_btn radio1">
	<input id="y1" name="connection_port_bot_angle" value="0" type="radio" class="r-input" <?php cps_checked(0, $conf['connection_port_bot_angle']); ?>>
</label>

Open in new window


And this CSS (just a part of it):

#cportsettings .r-input {
	margin: 8px;
}
#cportsettings .radio_btn {
	background: #e0e0e0;
	border: 1px solid #7b7b7b;
	-moz-border-radius: 16px;
	border-radius: 16px;
	
	-moz-box-shadow: 0px 0px 8px #aaa;
	-webkit-box-shadow: 0px 0px 8px #aaa;
	box-shadow: 0px 0px 8px #aaa;
}
#cportsettings .radio1 {
	position: absolute;
	top: 3px;
	left: 98px;
	z-index: 100;
}

Open in new window


- How can I change background color the label, when the input/radio is placed within it?
CSS

Avatar of undefined
Last Comment
COBOLdinosaur

8/22/2022 - Mon
COBOLdinosaur

I don't understand what you are asking.  What do you mean by "when the input/radio is placed within it?"


Cd&
Omer-Pitou

.radio_btn {
      background-color: red;
}
kgp43

ASKER
COBOLdinosaur; I was just referring to my input being placed within <label> tags, and the label need to change background when input radio is selected.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
kgp43

ASKER
Omer-Pitou; Background need to be changed when radio is selected :)
COBOLdinosaur

Give the label an id for easy reference and then use an on click for the radio

<label id="radlabel" for="y1" class="radio_btn radio1">
	<input id="y1" name="connection_port_bot_angle" value="0" type="radio" class="r-input" 
          onclick="document.getElementById('rsdlabel').style.backgroundColor='blue';"
       <?php cps_checked(0, $conf['connection_port_bot_angle']); ?>>
</label>

Open in new window


Cd&
kgp43

ASKER
that will not change background on the default selected one upon and will not de-select when a new radio is selected.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
kgp43

ASKER
Is it possible to make something like this with CSS:

"if radio is checked, then set background color of <label>"?

With this html setup:

<label for="y1" class="radio_btn radio1">
	<input id="y1" name="connection_port_bot_angle" value="0" type="radio" class="r-input" <?php cps_checked(0, $conf['connection_port_bot_angle']); ?>>
</label>

Open in new window

ASKER CERTIFIED SOLUTION
COBOLdinosaur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.