Change css of radiolist in yii2 - css

I have some radiolist in yii2 as following -
<?php
echo $form->field($model, 'wp_spost1')->radioList(['Yes'=>'Yes','No'=>'No','NA'=>'NA'])->label(false);
?>
It dissolves to following HTML
<div id="workpermit-wp_spost1" aria-required="true" aria-invalid="false"><div class="radio"><label><input type="radio" name="Workpermit[wp_spost1]" value="Yes" data-index="0"> Yes</label></div>
<div class="radio"><label><input type="radio" name="Workpermit[wp_spost1]" value="No" data-index="1"> No</label></div>
<div class="radio"><label><input type="radio" name="Workpermit[wp_spost1]" value="NA" checked="" data-index="2"> NA</label></div></div>
The css I'm trying to use is below -
.radio label
{
position:relative;
display: inline-block;
margin: 2px 2px;
padding: 2px;
width: 35px;
background: #ffffff;
border: 1px solid #008eff;
border-radius: 4px;
}
.radio input[type="radio"]:checked
{
box-shadow: 0 0 0 3px orange;
}
.radio input:checked {
color: red;
border: 10px solid #fff;
}
Current output
What I'm trying to achieve is that, when a radio button is checked, the border should be 10px wide and colour (of both the text and the border) should change. But I'm unable to target the border and the label.
Please help.
EDIT
I was trying different settings and made some changes in the HTML and css as below -
HTML - (Please note the label tag for earlier and now)
<div id="workpermit-wp_spost1" aria-required="true" aria-invalid="false">
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="Yes"><label>Yes</label></div>
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="No"><label>No</label></div>
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="NA"><label>NA</label></div>
</div>
CSS
.radio input[type="radio"]:checked
{
box-shadow: 0 0 0 3px orange;
}
.radio input[type="radio"]:checked + label {
color: red;
border: 10px solid #fff;
}
This combination is working. But unfortunately I cannot change the HTML manually. So the HTML I cannot change. can we anyway select the label on the earlier HTML setting.

You can change HTML. if you want at the end the code
<div id="workpermit-wp_spost1" aria-required="true" aria-invalid="false">
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="Yes"><label>Yes</label></div>
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="No"><label>No</label></div>
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="NA"><label>NA</label></div>
</div>
You can do something like this
echo $form->field($model, 'wp_spost1')->radioList(['Yes'=>'Yes','No'=>'No','NA'=>'NA'], ['item' => function($index, $label, $name, $checked, $value) {
if ($checked) {
$checkedText = 'checked="checked"';
} else {
$checkedText = '';
}
$return = '<div class="radio">';
$return .= ' <input id="workpermit-wp_spost1_' . $index . '" type="radio" name="' . $name . '" value="' . $value . '" ' . $checkedText . '>';
$return .= '<label for="workpermit-wp_spost1_' . $index . '">'. ucwords($label).' </label></div>';
return $return;
}
])->label(false);

Related

How to override CSS class over input[type]?

I am trying to override the input type
input[type="number"] {
width: 100px;
}
with the following css classes.
.choice_num{
width: 83px;
text-align:right;
padding: 2px;
font-weight: bold;
}
.choice_num_1{
width: 82px;
text-align:right;
padding: 2px;
font-weight: bold;
margin-right: 2px;
}
.float_nums{
width: 62px;
text-align:right;
padding: 2px;
font-weight: bold;
}
but it doesn't seem to work. Any ideas?
This is the code that you asked (sorry it didn't occur to me to add it.)
<input type="number" class="choice_num" step="<?php echo $epilogi['posotita']; ?>" min="<?php echo $epilogi['posotita']; ?>" value="<?php echo $epilogi['posotita']; ?>" onchange="calculate()" id="a1" name="posotita">
<input type="text" class="tmxs" value="KG" readonly="readonly" name="monmetr">
<input type="number" class="choice_num_1" value="<?php echo $epilogi['timi']; ?>" id="a2" readonly="readonly">
<?php } ?>
<input type="number" class="float_nums" value="<?php echo number_format((float)$sum, 2, '.', ''); ?>" id="a3" readonly="readonly">
Just add input before them, like this,
input[type="number"] {
background-color: orange
}
input.choice_num {
background-color: blue
}
input.choice_num_1 {
background-color: green
}
input.float_nums {
background-color: red
}
<input type="number" />
<input type="number" class="choice_num" />
<input type="number" class="choice_num_1" />
<input type="number" class="float_nums" />
By doing it the specificity of the later selectors increase and thus ur css works,
Just add more priority to it. Fast way to do it:
Instead of .choice_num select input.choice_num

Style label with radiobutton inside

I have a label I need styled depending on the state of the checkbox inside. Unfortunately I am constrained about changing the html structure! (Last resort is a javascriptsolution).
Is it even possible with a html structure as below
.like-this {
border: 1px solid black;
background: white;
color: black;
padding: 2px 4px;
}
.selected {
background: red;
color: white;
}
<label>
<input type="radio" name="field_123" value="Yes" class="Radio-Button">
I need same border
</label>
<label>
<input type="radio" name="field_123" value="No" class="Radio-Button"">
I need same border
</label>
<br/>
<span class="like-this">Not Selected</span>
<span class="like-this selected">Selected</span>
let form = document.querySelector( "form" );
form.addEventListener( "change", ( evt ) => {
let trg = evt.target,
trg_par = trg.parentElement;
if ( trg.type === "radio" && trg_par && trg_par.tagName.toLowerCase() === "label" ) {
let prior = form.querySelector( 'label.checked input[name="' + trg.name + '"]' );
if ( prior ) {
prior.parentElement.classList.remove( "checked" );
}
trg_par.classList.add( "checked" );
}
}, false );
label {
background: #ddd;
padding: 2px 10px 2px 0;
border: 1px solid #000;
}
label.checked {
background: #000;
color: white;
}
input{display:none;}
<form>
<label>
<input type="radio" name="field_123" value="Yes" class="Radio-Button">
I need same border
</label>
<label>
<input type="radio" name="field_123" value="No" class="Radio-Button"">
I need same border
</label>
</form>
input{display:none;}
label{
border: 1px solid #ddd;
cursor: pointer;
padding: 5px 20px;
}
input[type="radio"]:checked + label{
background:#000;
color:#fff;
}
<input type="radio" id="radio1" name="field_123" value="Yes" class="Radio-Button">
<label for="radio1">I need same border</label>
<input type="radio" id="radio2" name="field_123" value="No" class="Radio-Button"">
<label for="radio2">I need same border</label>

Style radio inputs as button when input is within label tag

My html:
<div class="product-addon product-addon-extra-tip">
<p class="form-row form-row-wide addon-wrap-2004-extra-tip-0-0">
<label><input type="radio" class="addon-radio" name="addon-2004-extra-tip-0[]" value="2">2</label>
</p>
<p class="form-row form-row-wide addon-wrap-2004-extra-donation-to-trafficking-survivors-0-1">
<label><input type="radio" class="addon-radio" name="addon-2004-extra-tip-0[]" value="5">5</label>
</p>
</div>
I'm trying to style these radio inputs to look like buttons, and I'm almost there. The problem is that given the current construct (which I can't directly change), I can't figure out how to make the :checked option look different than the rest.
You can see in the jsfiddle where I'm falling short. Is this possible?
http://jsfiddle.net/2gdotu21/1/
Via CSS, input set in front of label and correct attribute used, you can apply a different style if input is :checked or not.
See: https://www.w3.org/wiki/HTML/Elements/label & further more https://www.w3.org/TR/WCAG20-TECHS/H44.html
label {/* button unchecked add your style*/
color:red
}
label:before {/* button checked add your style*/
content:'$';
font-size:1rem;
}
input:checked + label {
color:green;
}
[type=radio]{ /* hide it ? use any methode but display:none; */
position:absolute;
right:200%;
}
<input type="radio" class="addon-radio" name="addon-2004-extra-tip-0[]" value="2" id="addon-2004-extra-tip-0[]" />
<label for="addon-2004-extra-tip-0[]">2</label>
<input type="radio" class="addon-radio" name="addon-2004-extra-tip-0[]" value="2" id="addon-2004-extra-tip-0[1]" />
<label for="addon-2004-extra-tip-0[1]">300</label>
<input type="radio" class="addon-radio" name="addon-2004-extra-tip-0[]" value="2" id="addon-2004-extra-tip-0[2]" />
<label for="addon-2004-extra-tip-0[2]">14</label>
<!-- same name to allow only one checked in this demo -->
else with your structure, integrate the radio within the design of the button http://codepen.io/gc-nomade/pen/LketK (oldish glassy button)
example of your code to change bg color
.product-addon-extra-tip label {
float: left;
width: auto;
min-width: 60px;
margin: 3px;
border-radius: 4px;
border: 1px solid #D0D0D0;
overflow: auto;
color: black;
font-size: 1.2rem;
text-align: center;
padding: 5px 0;
display: block;
line-height: 1.3rem;
}
.product-addon-extra-tip label input {}
.product-addon-extra-tip label:before {
content: '$';
}
label {
position: relative;
}
input {
position: absolute;
top: -15px;
z-index: -1;
box-shadow: 0 0 0 200px tomato;
}
input:checked {
box-shadow: 0 0 0 200px green;
}
<div class="product-addon product-addon-extra-tip">
<p class="form-row form-row-wide addon-wrap-2004-extra-tip-0-0">
<label><input type="radio" class="addon addon-radio" name="addon-2004-extra-tip-0[]" data-raw-price="0" data-price="" value="2"> 2 </label>
</p>
<p class="form-row form-row-wide addon-wrap-2004-extra-tip-0-1">
<label><input type="radio" class="addon addon-radio" name="addon-2004-extra-tip-0[]" data-raw-price="0" data-price="" value="5"> 5 </label>
</p>
</div>

Keeping CSS elements inline when window shrinks

I have a form that wont stay aligned when I shrink the page. The div2 will move over to the left and intrude on div1 and the button positions become all jumbled. I have been reading up on css and thought the way to go was making a wrapper div then two child divs for my input types but it doesnt seem to work. I have tried all sorts of things I have found all to no avail. Ideally I would like the elements to all shrink proportionally and stay alaigned as the window shrinks. Absent that I would at least like the elements to just disappear off screen as it shrinks with scroll bars. Any help is musch appreciated.
HTML:
<form action="updated_tt.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo $id; ?>" />
<div id="wrap">
<div id="div1">
Trouble Report/Request:<br/>
<textarea class="tt_fld5" name="ud_problem" maxlength="300" rows="3" wrap=HARD ><?php echo $problem; ?></textarea> <br/>
</div>
<div id="div2">
Action Taken: <br/>
<textarea class="tt_fld5" name="ud_act_tkn" maxlength="300" cols="40" rows="3" wrap=HARD ><?php echo $act_tkn; ?></textarea>
</div>
</div>
<br/>
<br/>
<?php
/* Here we create an array of the drop down list choices, then go thru the array one by one and check for the "selected" attribute.
If the value retrieved from MySQL equals the ddown_options array element then construct <option> line with the "selected" value, else construct
a normal <option> line. Note We have to Make this a form here.*/
$option_to_preselect = $tkt_status;
$ddown_options = array
(
'Open',
'Referred',
'Closed',
);
echo '<span class=tt_fld>Ticket Status: ' . '</span>' . '<br />';
$arrlength=count($ddown_options);
print '<select name="ud_ticket_status" id="input_select">';
for ($x=0;$x<$arrlength;$x++)
{
if ($ddown_options[$x] == $option_to_preselect)
{
print ' <option value="' . $ddown_options[$x] . '"' . ' selected="selected">' . $ddown_options[$x] . '</option>';
}
else {
print ' <option value="' . $ddown_options[$x] . '">' . $ddown_options[$x] . '</option>';
}
}
print '</select>';
echo '<br />';
echo '<br />';
/* For Assigned Tech...*/
echo '<span class=tt_fld>Assigned To: ' . '</span>' . '<br />';
$option_to_preselect = $assgnd_tech;
$ddown_options = array
(
'Unassigned',
'***',
'***',
'***',
'***',
);
$arrlength=count($ddown_options);
print '<select name="ud_assgnd_tech" id="input_select">';
for ($x=0;$x<$arrlength;$x++)
{
if ($ddown_options[$x] == $option_to_preselect)
{
print ' <option value="' . $ddown_options[$x] . '"' . ' selected="selected">' . $ddown_options[$x] . '</option>';
}
else {
print ' <option value="' . $ddown_options[$x] . '">' . $ddown_options[$x] . '</option>';
}
}
print '</select>';
?>
<br />
<center><button type="submit" class="btn btn-primary btn-lg" onclick="updated.php">Update Trouble Ticket</button></center>
<br />
<!-- Indicates a dangerous or potentially negative action -->
<center><button type="button" class="btn btn-danger" onclick="Del_Function()">Delete Trouble Ticket</button></center>
</form>
CSS:
#wrap {
overflow: hidden;
padding: 2px 0 0 0;
width: 94%;
margin: 25 auto;
}
#div1 {
font-weight: bold;
font: x-large serif;
font-weight: bold;
float: left;
width: 47%;
margin-top: 10px;
}
#div2 {
font: large serif;
float: right;
width: 47%;
margin-top: 10px;
font-weight: bold;
font-size: x-large;
}
The float attribute is specifically used to allow content to flow around block content depending on page dimensions. Instead of floating your content divs, try relative positioning.
Here's the CSS that worked for me just for the record:
#wrap {
overflow: hidden;
padding: 2px 0 0 0;
width: 1200px;
min-height:150px;
margin: 25 auto;
}
#div1 {
font: large serif;
font-weight: bold;
position: relative;
left: 10px;
width: 300px;
font-size: x-large;
max-width:300px;
}
#div2 {
font: large serif;
font-weight: bold;
font-size: x-large;
position: relative;
left: 600px;
width: 300px;
bottom:155px;
}

fixed div with dynamic content not scrolling

I have a fixed div with dynamic loaded li elements. Now I want the div-content to scroll when there are more than 9 li elements and a scroll-bar:
This is what it looks like:
At the moment the fixed div goes on over the footer and the content can not be scrolled.
Here is the css for all divs:
#fixed-div {
position: fixed;
width: 30%;
margin-top:290px;
padding-top:20px;
padding-bottom: 20px; /* must be same height as the footer */
background-color: rgba(255, 255, 255, 0.60);
min-height: 100%;
}
#absolute-div {
padding: 15px;
background-color: rgba(255, 255, 255, 0.60);
margin-bottom: 10px;
position: relative;
height: 200px;
}
#footer {
position: relative;
margin-top: -33px; /* negative value of footer height */
height: 20px;
line-height: 33px;
border-bottom:20px solid #fff;
text-align: left;
background-color:#fff;
padding-left:10px;
}
#map_canvas { /* background */
clear:left;
float: left;
width: 100%;
min-height: 100%;
z-index:-1001;
/* height: 530px;*/
-webkit-box-shadow: 0px 0px 10px #888;
-moz-box-shadow: 0px 0px 10px #888;
}
And here's the HTML:
<body>
<div id="searchbox">
<div id="absolute-div" class="clear-block">
<form method="post" action="./index.php" accept-charset="UTF-8" method="post" id="clinic-finder-form" class="clear-block" class="clear-block">
<label for="edit-gmap-address">Standort angeben und Vorteile in der Umgebung finden: </label>
<input type="text" maxlength="128" name="address" id="address" size="60" value="" class="form-text" autocomplete="off" />
<?php
// support unicode
mysql_query("SET NAMES utf8");
$cats = $db->get_rows("SELECT categories.* FROM categories WHERE categories.id!='' ORDER BY categories.cat_name ASC");
?>
<select name="products" class="form-select" id="edit-products" ><option value="">Alle Kategorien</option>
<?php if(!empty($cats)): ?>
<?php foreach($cats as $k=>$v): ?>
<option value="<?php echo $v['id']; ?>"><?php echo $v['cat_name']; ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<input type="submit" name="op" id="edit-submit" value="Vorteile finden" class="btn btn-primary" />
<input type="hidden" name="form_build_id" id="form-0168068fce35cf80f346d6c1dbd7344e" value="form-0168068fce35cf80f346d6c1dbd7344e" />
<input type="hidden" name="form_id" id="edit-clinic-finder-form" value="clinic_finder_form" />
<input type="button" name="op" onclick="document.location.href='newstore.php'" id="edit-submit" value="Unternehmen vorschlagen" class="btn btn-primary" />
</form>
</div></div>
<div id="fixed-div">
<div id="clinic-finder" class="clear-block">
<div id="results">
<ol style="display: block; " id="list"></ol>
</div>
</div>
</div>
<div id="map_canvas"></div>
<div id="footer">© 2008-2013 Ihr Vorteilsclub - Impressum</div>
Thanks a lot! Marcel
Add this to your css:
#results {
height: 100%;
overflow-y: scroll; /* adds scrollbar */
}
You can do this with absolute positioning. You still need overflow-y: scroll. Absolutely position the top of the dynamic section to the total height of the fixed elements above it and the bottom to the total height of the fixed elements below it. May need to tweak slightly but that should do the trick of consuming all the intermediate space and scrolling the overflow.

Resources