Jump to content

border based on radio selection problem


SF23103

Recommended Posts

Hello,

 

I am having difficulty with this one.  I am trying to change the border around the entire div (e.g. #option1) instead of just the text.  As you can see, when you click each radio button it changes the border around the option text, but not the entire div.  Any suggestions?

 

JSFIDDLE:   https://jsfiddle.net/1hdv2n3h/1/

 

HTML

<div id="wine_club_selection">

<div id="option1">
<p><input type="radio" name="club_type" checked="checked" value="option 1"><br/>
<span class="bold_text">Option 1</span><br/>
3 Bottles<br/>
15% Discount<br/></p></div>

<div id="option2">
<p><input type="radio" name="club_type" value="option 2" ><br />
<span class="bold_text">Option 2</span><br />
6 Bottles<br />
20% Discount<br/>
</p></div>

<div id="option3">
<p><input type="radio" name="club_type" value="option 3"><br>
<span class="bold_text">Option 3</span><br />
12 Bottles<br />
25% Discount<br />
</p></div>

</div>

CSS

#wine_club_selection {
	height:200px;
	width:800px;
}

#option1 {
float:left;
width:266px;
}

#option1 p {
	text-align:center;
}

#option2 {
float:left;
width:266px;
}

#option2 p {
	text-align:center;
}

#option3 {
float:right;
width:266px;
text-align: center;
}

#option3 p {
	text-align:center;
}


.bold_text {
	font-weight:800;
}


#option1 input[type="radio"]:checked ~ *{ 
        border: thin solid #F00;!important;
}

#option2 input[type="radio"]:checked ~ *{ 
        border: thin solid #F00;!important;
}

#option3 input[type="radio"]:checked ~ *{ 
        border: thin solid #F00;!important;
}
Link to comment
Share on other sites

You can't achieve what you are trying to do with just CSS alone.  You are trying to alter the style of a parent element and CSS doesn't have a parent selector.  You could maybe get away with creating an underlay element after the input using absolute positioning and change that using a sibling selector javascript using jquery would be far cleaner.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.