dynamic div border based on radio button selection - css

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/
<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;
}
.billing_table input {
font-size:18px;
color:#620101;
}
#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;
}

I'm a bit anal-retentive about good-quality HTML, so I tidied yours up a little to make it more semantically-correct.
You can't use CSS to select the "parent" of an element -- only "sibling" elements that come after it -- so you have to sort-of fake it.
.options {
height:200px;
width:800px;
text-align:center;
}
.options li{
display:inline-block;
width:30%;
}
.options p{
margin:0;
}
.options header p{
font-weight:bold;
}
.options li div{
padding-top:1em;
}
.options li input{
position:relative;
top:2em;
}
.options li input:checked+div{
border:1px solid #f00;
}
<ul class="options">
<li>
<input type="radio" name="option" checked />
<div>
<header><p>Option 1</p></header>
<p>3 bottles</p>
<p>15% discount</p>
</div>
</li>
<li>
<input type="radio" name="option" />
<div>
<header><p>Option 2</p></header>
<p>6 bottles</p>
<p>20% discount</p>
</div>
</li>
<li>
<input type="radio" name="option" />
<div>
<header><p>Option 3</p></header>
<p>12 bottles</p>
<p>25% discount</p>
</div>
</li>
</ul>

Related

place input checkbox in same line of label

i am struggling to place input check-box in same line x-horizontal as in label. My check-box is placing in 2nd line. I have a div with background to image then label and then check-box. The margin between image and label div and margin between label and check need to be same. Many thanks in advance.
<div id="map_Marker_Check_Block">
<div class="markerDiv" id="maker_school"><div class="marker_label">School</div> <input class="marker_ckeckbox" name="markerType" value="school" type="checkbox" /> </div> <br />
<div class="markerDiv" id="maker_gym"> <div class="marker_label">Gym</div> <input class="marker_ckeckbox" name="markerType" value="gym" type="checkbox" /> </div><br />
</div>
css
#map_Marker_Check_Block {
background-color:yellow;
display:block;
position:absolute;
width:20em;
height:400px;
top:0;
right:0;
z-index:10;
overflow-y:auto;
}
.marker_label {
margin-left:50px;
line-height:48px;
width:130px;
background-color:green;
}
.marker_ckeckbox {
float:right;
}
.markerDiv {
width:19em;
height:48px;
margin-left:5px;
}
#maker_school { background: url("img1.png") no-repeat; }
#maker_gym{ background: url("img2.png") no-repeat; }
http://jsfiddle.net/XUErp/
.marker_label {
float:left;
margin-left:50px;
line-height:48px;
width:130px;
background-color:green;
}
.marker_ckeckbox {
margin-top:15px;
float:right;
}
Use TOP and POSITION styles for checkbox:
.marker_ckeckbox {
float: right;
position: relative;
top: -35px;
}
But, I think the elements must be structured in a different way.
Or as Musa said use label instead of div:
Sample: http://jsfiddle.net/qaprB/1/
try this
<div class="markerDiv" id="maker_school"><label class="marker_label">School</label> <input class="marker_ckeckbox" name="markerType" value="school" type="checkbox" /> </div> <br />
<div class="markerDiv" id="maker_gym"> <label class="marker_label">Gym</label> <input class="marker_ckeckbox" name="markerType" value="gym" type="checkbox" /> </div><br />
css
.marker_ckeckbox {
float:right;
position: relative;
top: -35px;
}
.marker_label {
display:block;
}

Align a dynamically created image in the right side of a div

I am trying to create a shopping list. The list is dynamically created using Javascript (jQueryUI). I want the thrash cans next to be on the right side (where this blue dots that I draw are). I tried to do it using left or style="right:350px" and float:right in tag but it didn't work.
Here is my code where it's row is generated:
var row=$('<div class"productsclass" id='+selectedproducts[i]+' style="width:400px">
<label style="font-size:20px">'+selectedproducts[i]+'</label><input type="text"
name="Quantity" value="1" id='+thesi+'><img class=delete
src="http://b.dryicons.com/images/icon_sets/handy_part_2_icons/png/128x128/recycle_bin.png"
height="22" width="22" style="right:350px"></div>');
rowID++;
$("#productstable").append(row);
Here is the html:
<div id="maindiv" class="maindiv">
<input id="autocomplete_text_field">
<button id="add_product_button">Add product</button>
<form action="#" id="productstable" name="productstable">
<p></p>
</form>
</div>
</body>
and here is the CSS:
#body{
background-color: #6E0D25
}
#maindiv {
position:absolute;
top: 50%;
left: 50%;
width:30em;
height:18em;
margin-top: -9em; /*set to a negative number 1/2 of your height*/
margin-left: -15em; /*set to a negative number 1/2 of your width*/
/*border: 1px solid #ccc;*/
background-color: #6E0D25;
}
#productstable
{
background-color:#F1EBE4;
border-radius:10px;
width:400px;
}
#product
{
width:380px;
}
#autocomplete_text_field
{
width:200px;
height:40px;
border-radius:10px;
}
#add_product_button
{
width:200px;
height:50px;
border-radius:10px;
}
How can I do it?
(Sorry if it is a very useless question, It's almost the first time I use CSS)
Solved after user2313440's answer:
Change img class=delete to img class="delete" then add float:right; to it in CSS.
just a simple rearrange of your img, and using float: right;
try this code instead:
var row=$(' <div class "productsclass" id='+selectedproducts[i]+' style="width:400px">
<img class=deletesrc="http://b.dryicons.com/images/icon_sets/handy_part_2_icons/png/128x128/recycle_bin.png" height="22" width="22" style="float: right;">
<label style="font-size:20px">'+selectedproducts[i]+'</label>
<input type="text" name="Quantity" value="1" id='+thesi+'>
</div>');
rowID++;
$("#productstable").append(row);

Positioning a menu list underneath a textbox with CSS

I'm struggling with CSS to get my search box and list to look like how I want it. I want the list to be attached to the bottom of the textbox and I have no idea how to do that. Here is a short of what I've got so far...
<style>
ul.drop{display:inline-block;}
ul.drop, ul.drop li { list-style: none; margin: 0; padding: 0; background: #ECF1F3; color: #28313F; }
ul.drop li.hover, ul.drop li:hover { position: relative; z-index: 599; background: #1e7c9a;}
</style>
</head>
<body>
<label for="someinput">Search Ingredients</label>
<input id="someinput">
<ul id="menu" class="drop" style="overflow:auto; max-height:200px;">
<li>ingredient1</li>
<li>ingredient2</li>
<li>ingredient3</li>
<li>ingredient4</li>
<li>ingredient5</li>
</ul>
<label for="qty"></label>
<input type="text" size="5" name="qty" id="qty" />
g
<button type="submit" name="add" id="add" value="Add">Add</button>
</body>
The list is currently showing to the right of the box, I would like it to be directly underneath the textbox. I was considering a container div for the list, but wasn't sure if that was necessary.
Thanks for your help.
You have two options here both would involve changing you html to the following:
<div class="inputHolder">
<label for="left someinput">Search Ingredients</label>
<input id="someinput" /><br />
<ul id="menu" class="drop" style="overflow:auto; max-height:200px;">
<li>ingredient1</li>
<li>ingredient2</li>
<li>ingredient3</li>
<li>ingredient4</li>
<li>ingredient5</li>
</ul>
</div>
<div class="inputHolder">
<label for="qty">g</label>
<input type="text" size="5" name="qty" id="qty" />
<button type="submit" name="add" id="add" value="Add">Add</button>
</div>
Then if you want to have your list appear above any further content (ie content will be pushed down), you need the following extra styles:
.inputHolder {float:left; margin-right:10px;}
#menu {margin-left:7.5em}
http://jsfiddle.net/FteVT/3/
If you want your list to appear on top of (overlapping) any further content, you can use these styles:
.inputHolder {float:left; margin-right:10px; position:relative;}
#menu {position:absolute; left:7.5em; top:1.5em;}
http://jsfiddle.net/FteVT/4/
sorry this is'nt really an answer but you might be interested in jquery chosen component, which does the job : jQuery Chosen
When I run your code in a fiddle, I get this: http://jsfiddle.net/Lera/VG642/
With this CSS
ul.drop{display:inline-block;}
ul.drop, ul.drop li { list-style: none; margin: 0; padding: 0; background: #ECF1F3; color: #28313F; }
ul.drop li.hover, ul.drop li:hover { position: relative; z-index: 599; background: #1e7c9a;}
The list is under the search box and its label, not to the right as you said. I don't think I'm clear where you want it from your question.
Did you want the list indented? Can you clarify a bit more?
To start you have a href before li that needs to be moved inside of the li, also remove display: block-inline and leave block only, then add #someinput { display: block}
<label for="someinput">Search Ingredients</label>
<input id="someinput">
<ul id="menu" class="drop" style="overflow:auto; max-height:200px;">
<li> ingredient1</li>
<li> ingredient2</li>
<li> ingredient3</li>
<li> ingredient4</li>
<li> ingredient5</li>
</ul>
<label for="qty"></label>
<input type="text" size="5" name="qty" id="qty" />
<button type="submit" name="add" id="add" value="Add">Add</button>
CSS Portion
ul.drop{display:block;}
ul.drop, ul.drop li { list-style: none; margin: 0; padding: 0; background: #ECF1F3; color: #28313F; }
ul.drop li.hover, ul.drop li:hover { display: block; position: relative; z-index: 599; background: #1e7c9a;}
#someinput {
display:block;
}
See my jsfiddle here http://jsfiddle.net/cornelas/P7z7d/embedded/result/

HTML - Compatibility Mode - Button Not Appearing

I have a basic page which is used in an iFrame on an intranet site. It is generated using ASP.NET, the generated source is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title><link rel="Stylesheet" type="text/css" href="css/EDT.css" />
<script type="text/javascript" language="javascript" src="includes/ADIServices.js"></script>
</head>
<body>
<form name="form1" method="post" action="ADIServices.aspx?type=2&typename=contact&id=%7bA2755D17-67FF-4539-8AAE-327038D5E618%7d&orgname=RSAADI&userlcid=1033&orglcid=1033" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTg3NDY0NDE0Mg8WBh4IdXNlcm5hbWUFEG5rZW5ueUB2dWxjYW4uaWUeCWhhc2FjY2Vzc2ceBWFkaWlkKClYU3lzdGVtLkd1aWQsIG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OSRhMjc1NWQxNy02N2ZmLTQ1MzktOGFhZS0zMjcwMzhkNWU2MTgWAgIDD2QWAgIDDw8WAh4EVGV4dAUQbmtlbm55QHZ1bGNhbi5pZWRkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYDBQ9yYlVzZXJBY2Nlc3NZZXMFDnJiVXNlckFjY2Vzc05vBQ5yYlVzZXJBY2Nlc3NOb1LW6lJTh7HRxc/r9DmBabkk6Q+U" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBwKT+7PEDAKl1bK4CQL62KvxCQLU6/3GAwLfl6DKCAK5ieyiCQLHst2vAuS7asmw5PqvB/FNK/KEPjCqeGEz" />
</div>
<div id="content">
<div id="username">
<span id="lblUsername" class="label">Username</span>
<input name="txtUsername" type="text" value="nkenny#xxxxxxx.xx" id="txtUsername" disabled="disabled" class="textbox" />
</div>
<div id="access">
<span id="lblUserAccess" class="label">Portal Access</span>
<div id="useraccessradiobuttons">
<span class="radiobutton"><input id="rbUserAccessYes" type="radio" name="rblUserAccess" value="rbUserAccessYes" checked="checked" /><label for="rbUserAccessYes">Yes</label></span>
<span class="radiobutton"><input id="rbUserAccessNo" type="radio" name="rblUserAccess" value="rbUserAccessNo" /><label for="rbUserAccessNo">No</label></span>
</div>
</div>
<div id="passwordchange">
<div id="newpassword">
<span id="lblNewPassword" class="label">New Password</span>
<input name="txtNewPassword" type="text" id="txtNewPassword" class="textbox" />
</div>
<div id="newpasswordrepeat">
<span id="lblRepeatPassword" class="label">Repeat Password</span>
<input name="txtRepeatPassword" type="text" id="txtRepeatPassword" class="textbox" />
</div>
<a id="lnkShowChangePasswordFields" class="link" OnClick="javascript:ShowHidePasswordFields()">Change Password</a>
</div>
</div>
<div id="submit">
<input type="submit" name="cmdSave" value="Save" onclick="return ValidateFields();" id="cmdSave" />
<span id="lblStatus"></span>
</div>
</form>
</body>
</html>
I have a stylesheet assoiciated with this:
body
{
background-color:#EAF3FF;
font-family:Tahoma;
font-size:11px;
}
input
{
font-family:Tahoma;
font-size:11px;
}
#content
{
width:350px;
}
.label
{
width:30%;
height:5px;
position:relative;
top:7px;
float:left;
}
.radiobutton
{
width:21%;
height:5px;
position:relative;
top:7px;
float:left;
}
.link
{
width:50%;
height:5px;
position:relative;
top:27px;
float:left;
color:blue;
text-decoration:underline;
}
.textbox
{
width:70%;
position:relative;
float:right;
}
#cmdSave
{
position:relative;
float:left;
top:50px;
left:-177px;
}
#lblStatus
{
position:relative;
float:left;
left:-170px;
top:53px;
color:red;
}
#useraccessradiobuttons
{
width:100%;
position:relative;
}
#newpassword
{
display:none;
position:relative;
top:22px;
}
#newpasswordrepeat
{
display:none;
position:relative;
top:22px;
}
When some users are browsing to this page the Save button is not appearing. I first came across this issue and released that Compatibility mode was turned on, when I turned it off the issue disappeared. This was fine, I instructed users to ensure that compatibility mode was off.
However now some users are reporting that the button is not appearing, even when compatibility mode is off. Users are using IE8.
I know there is a meta tag that can force the browser to emulate IE7/8/9, is this the way I should go, and if so, which of these versions should I be using based on the code above? It can be assumed that only IE will be used
Thanks in advance,
Neil
EDIT
Based on the answer given below I modified my stylesheet as follows:
body
{
background-color:#EAF3FF;
font-family:Tahoma;
font-size:11px;
padding-top: 5px;
padding-left:5px;
}
input
{
font-family:Tahoma;
font-size:11px;
}
#useraccessradiobuttons
{
width:60%;
display:inline;
}
#content
{
width:350px;
padding-bottom:10px;
}
#username
{
padding-bottom:7px;
}
#newpassword
{
padding-bottom:4px;
}
#passwordchange
{
padding-bottom:7px;
}
#access
{
width:100%;
padding-bottom:7px;
}
.label
{
float:left;
width:30%;
}
.radiobutton
{
padding-right:30px;
}
.link
{
width:50%;
height:5px;
color:blue;
text-decoration:underline;
}
.textbox
{
width:60%;
}
#cmdSave
{
width:60px;
}
#lblStatus
{
color:red;
}
#useraccessradiobuttons
{
display:inline;
}
#newpassword
{
display:none;
}
#newpasswordrepeat
{
display:none;
}
You seem to have a lot of unnecessary styling applied. The problem seems to be the
left:-177px;
on the #cmdSave.
However, a lot more of your styling can be removed to whilst keeping the same layout http://jsfiddle.net/jfsw4/6/
Then you can format more with margins and padding.

Radio Buttons Inline and Centered with Labels

I have the following form:
<form action="post.php" method="POST">
<fieldset>
<div class="ratingClass">
<input type="radio" class="radio" name="rate" value="1" id="1"/>
<label for="1">1</label>
<input type="radio" class="radio" name="rate" value="2" id="2"/>
<label for="2">2</label>
<input type="radio" class="radio" name="rate" value="3" id="3"/>
<label for="3">3</label>
<input type="radio" class="radio" name="rate" value="4" id="4"/>
<label for="4">4</label>
<input type="radio" class="radio" name="rate" value="5" id="5"/>
<label for="5">5</label>
</div>
</fieldset>
<input type="submit" value="Rate">
</form>
Styled by the following CSS:
fieldset {
overflow:hidden;
}
.ratingClass {
float:left;
clear:none;
}
label {
float:left;
clear:none;
display:block;
padding: 2px 1em 0 0;
}
input[type=radio], input.radio {
float:left;
clear:none;
margin: 2px 0 0 2px;
}
It's all inside of another div that has text-align: center; styling.
I realize that behavior is because of the floats, but if I remove them then the radio buttons no longer display inline.
How can I have them inline and centered?
You don't need to float everything nor make the labels block elements. Replacing your CSS with this causes everything to be centered:
fieldset {
overflow: hidden;
}
label {
padding: 2px 1em 0 0;
}
input[type=radio], input.radio {
margin: 2px 0 0 2px;
}
The <div class="ratingClass"> is also superfluous and can be removed.
Try making the .ratingClass container either:
.ratingClass {
float:left;
clear:none;
width: 100%;
text-align: center;
}
or
.ratingClass {
float:none;
text-align: center;
}
If you can cope with a fixed width for the ratingClass div you could do it as follows…
.ratingClass {
width:300px; /* insert desired width here */
margin:auto;
}

Resources