assign pseudoclass to a label within a specific div - html

I would like to assign a pseudo-css class to a <label> within a div with a a specific #id
My markup:
<div id="square">
<input class="time" id="show_45min" type="checkbox" name="time" value="45min">
<label for="show_45min" class="square">45 min</label><br>
<input class="time" id="show_60min" type="checkbox" name="time" value="60min">
<label for="show_60min" class="square">60 min</label><br>
</div>
and the css:
#square input[type=radio] {
display: none;
}
#square label:before {
content: "";
display: inline-block;
width: 16px;
height: 16px;
margin-right: 10px;
position: absolute;
left: 0;
bottom: 1px;
background-color: #aaa;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
}
problem is, that still every label on the page gets the content of label:before. But I just want it to assign to the labels within the div.
Thanks

http://jsbin.com/luhib/1/edit
input[id^=show_]{
display:none;
}
label[for^=show_]:before {
content: "";
display: inline-block;
vertical-align:baseline;
width: 1em;
height: 1em;
margin-right: 10px;
background-color: #aaa;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
}
input[id^=show_]:checked + label.square:before {
box-shadow: inset 0px 2px 15px 0px rgba(255, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
}

You may want to use the > direct child selector:
#square > label:before
More from MDN
The > combinator separates two selectors and matches only those
elements matched by the second selector that are direct children of
elements matched by the first. By contrast, when two selectors are
combined with the descendant selector, the combined selector
expression matches those elements matched by the second selector for
which there exists an ancestor element matched by the first selector,
regardless of the number of "hops" up the DOM.

Change this
#square label:before
to
#square > label:before

Related

input type="radio" - only choose second option?

I have an issue with my radio input.
It lets me change to the second option if im clicking on the label but it doesnt work for the first option. I can only choose the first option if im clicking on the selection-circle but i dont want to display it. It should work with a click on the text.
Any ideas?
.switch-field {
display: flex;
margin-bottom: 36px;
overflow: hidden;
justify-content: center;
}
.switch-field input {
position: absolute;
clip: rect(0, 0, 0, 0);
height: 100px;
width: 100px;
border: 1px;
/* overflow: hidden; */
}
.switch-field label {
background-color: #e4e4e4;
color: rgba(0, 0, 0, 0.6);
font-size: 14px;
line-height: 1;
text-align: center;
padding: 8px 10%;
margin-right: -1px;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
transition: all 0.1s ease-in-out;
}
.switch-field label:hover {
cursor: pointer;
}
.switch-field input:checked+label {
background-color: #cc7676;
box-shadow: none;
}
.switch-field label:first-of-type {
border-radius: 4px 0 0 4px;
}
.switch-field label:last-of-type {
border-radius: 0 4px 4px 0;
}
<div class="switch-field">
<input type="radio" id="strang1u3" name="switch-one" onchange="speichern(); clicksound()" />
<label for="strang1u2">Strang 1 & 3</label>
<input type="radio" id="strang2u4" name="switch-one" onchange="speichern(); clicksound()" />
<label for="strang2u4">Strang 2 & 4</label>
</div>
Your first label's for (strang1u2) and input's id (strang1u3) don't match. This may be causing this as the label isn't associated with the input.

Fix a colour for checkbox if condition is met

I have a seat plan for a hall and I am trying to create a seating booking system. Green indicates available and red indicates taken seats. I already managed to get the box turn green when checked. How do I make the checkbox red if a condition is met i.e. the seat is taken? Also, how do I make it stay red?
Below is a snippet of my code for row A.
<!--A-->
<tr>
<td>A</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<input type="checkbox" class="seats" name="selected[]" value="A26">
</td>
<td>
<input type="checkbox" class="seats" name="selected[]" value="A25">
</td>
<td>
<input type="checkbox" class="seats" name="selected[]" value="A24">
</td>
<td>
<input type="checkbox" class="seats" name="selected[]" value="A23">
</td>
<td>
<input type="checkbox" class="seats" name="selected[]" value="A22">
</td>
<td>
<input type="checkbox" class="seats" name="selected[]" value="A21">
This is the relevant CSS code.
.smallBox::before {
content: "";
width: 15px;
height: 15px;
display: inline-block;
margin-right: 10px;
}
.greenBox::before {
content: "";
background: Green;
}
.redBox::before {
content: "";
background: Red;
}
.emptyBox::before {
content: "";
box-shadow: inset 0px 2px 3px 0px rgb(255, 152, 0), 0px 1px 0px 0px rgba(255, 255, 255, .8);
-moz-box-shadow: inset 0px 2px 3px 0px rgb(255, 152, 0), 0px 1px 0px 0px rgba(255, 255, 255, .8);
-webkit-box-shadow: inset 0px 2px 3px 0px rgb(255, 152, 0), 0px 1px 0px 0px rgba(255, 255, 255, .8);
background-color: #fff;
}
.seats {
border: 1px solid red;
background: yellow;
}
.seatGap {
width: 40px;
}
.seatVGap {
height: 40px;
}
input[type=checkbox] {
width: 13px;
margin-right: 14px;
cursor: pointer;
}
input[type=checkbox]:before {
content: "";
width: 25px;
height: 18px;
border-radius: 5px;
/* Safari 3-4, iOS 1-3.2, Android 1.6- */
-webkit-border-radius: 5px;
/* Firefox 1-3.6 */
-moz-border-radius: 5px;
display: inline-block;
vertical-align: middle;
text-align: center;
border: 3px solid #ff9800;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
-moz-box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
-webkit-box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
background-color: #ffffff;
}
input[type=checkbox]:checked:before {
background-color: Green;
font-size: 15px;
}
Please help. Thank you.
You should change class attribute based if seat was picked by current user (green) or another (red)
input.green[type=checkbox]:checked:before {
background-color: Green;
font-size: 15px;
}
input.red[type=checkbox]:checked:before {
background-color: Red;
font-size: 15px;
}

How to make my checkboxes transparent

How do i make my checkboxes transparant? It does work with text fields and buttons but it doesnt seem to work with checkboxes.
This is the form of my code.
#checkbox {
width: 20px;
height: 20px;
cursor: pointer;
vertical-align: bottom;
color: black;
background-color: rgba(0, 0, 0, 0.08);
}
<div class="checkbox check-transparent">
<label>
<input type="checkbox" id="checkbox">Onthoud mij
</label>
</div>
The only thing that can be done for a regular checkbox is making it transparent by decreasing its opacity but it also lightens the tick mark inside if checked. A workaround is, having the checkbox wrapped in a div and changing the color of the checkbox when checked like shown in the snippet below:
#checkb {
width: 20px;
height: 20px;
cursor: pointer;
background: rgba(40,40,40,0.2);
color:black;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
position: relative;
left: -5px;
top: -5px;
}
#checkb:checked {
background: rgba(40,40,40,0.7);
}
.checkbox-container {
position: absolute;
display: inline-block;
margin: 20px;
width: 100px;
height: 100px;
overflow: hidden;
}
<div class="checkbox-container">
<input type="checkbox" id="checkb"/> Input
</div>
You can also (classic method that allows to restyle a checkbox crossbrowser following standards)
take input ahead and outside the label
link the label to its input via attribute for
use a pseudo on label to draw a checkbox via css and also apply size and background.
hide the checkbox
label {
display: inline-block;
}
#checkbox {
display: none;
}
label:before {
content: '';
cursor: pointer;
vertical-align: bottom;
color: black;
background-color: rgba(0, 0, 0, 0.1);
/* average checkbox styling */
line-height: 1.1em;
font-weight: bold;
text-align: center;
font-size: 20px;
height: 20px;
width: 20px;
display: inline-block;
box-shadow: inset 0 0 1px 1px rgb(153, 154, 154), inset 0 0 1px 2px white, inset 0 0 1px 2px white, inset 2px 2px 1px 1px rgb(182, 187, 192), inset -1px -1px 2px 1px rgb(182, 187, 192), inset 8px 8px 4px -4px rgb(182, 187, 192);
box-sizing: border-box;
}
:checked+label:before {
content: '\2713';
color: rgb(74, 95, 151);
}
:checked+label {
color: rgb(74, 95, 151);
}
label:hover {
color: rgb(28, 50, 125);
}
label:hover:before {
box-shadow: inset 0 0 1px 1px rgb(95, 133, 156), inset 0 0 1px 2px rgb(198, 237, 252), inset 0 0 1px 2px rgb(198, 237, 252), inset 2px 2px 1px 1px rgb(134, 203, 246), inset -1px -1px 2px 1px rgb(134, 203, 246), inset 8px 8px 4px -4px rgb(134, 203, 246);
}
<div class="checkbox check-transparent">
<input type="checkbox" id="checkbox">
<label for="checkbox"> Onthoud mij
</label>
</div>

Checkbox won't check IE8

I can't find a way to make the checkboxes checked in IE8. It's based on a Google Form, I re-used the same code to easily have an answer sheet. On top of that, the answers aren't sent.
I use this code
<li class="ss-choice-item">
<label>
<span class="ss-choice-item-control goog-inline-block">
<input type="checkbox" name="entry.637692828" value="Facebook" id="group_637692828_2" role="checkbox" class="ss-q-checkbox">
<label for="group_637692828_2"></label>
</span>
<span class="ss-choice-label">Facebook</span>
</label>
</li>
Here is the CSS, I wanted to custom the buttons, it works really fine in all other browsers.
.ss-q-checkbox {
display: none;
}
.ss-q-checkbox + label {
background-color: #fafafa;
border: 1px solid #cacece;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
padding: 9px;
border-radius: 3px;
display: inline-block;
position: relative;
margin-right: 4px;
}
.ss-q-checkbox + label:active, .ss-q-checkbox:checked + label:active {
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px 1px 3px rgba(0, 0, 0, 0.1);
}
.ss-q-checkbox:checked + label {
background-color: #e9ecee;
border: 1px solid #adb8c0;
color: #f87000;
}
.ss-q-checkbox:checked + label:after {
content:'\2714';
font-size: 14px;
position: absolute;
top: 0px;
left: 3px;
color: #f87000;
}
Could someone have the solution?
Thanks :)
You cannot use display:none (or visibility:hidden) on inputs with IE8 as it will treat it as if the input isn't there. Instead of hiding it using display try the following:
.ss-q-checkbox {
position:fixed; left:100%; top:0;
}

Check mark "\2714" not working?

I'm customizing a checkbox and it seems to be functioning but the unicode check isn't working... it's appearing as the text "\2714".
Here's my code:
.edd_price_option_1762 {
-webkit-appearance: none;
background-color: #fafafa;
border: 3px solid #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
padding: 9px;
border-radius: 0px;
display: inline-block;
position: relative;
top: 8px;
}
.edd_price_option_1762:active, .edd_price_option_1762:checked:active {
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px 1px 3px rgba(0, 0, 0, 0.1);
}
.edd_price_option_1762:checked {
background-color: #e9ecee;
border: 3px solid #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05), inset 15px 10px -12px rgba(255, 255, 255, 0.1);
color: #99a1a7;
}
.edd_price_option_1762:checked:after {
content:"\2714";
font-size: 19px;
position: absolute;
top: 0px;
left: 3px;
color: #49a6db;
}
You are missing a back slash \ in your markup.
It should be content: "\2714"; currently it is: content: "2714";
jsFiddle demo - the code you posted is correct - it just doesn't match up with that is being implemented on the page.
The dev tools state that your css is:
.edd_price_option_1762:checked:after {
content: "2714 ";
font-size: 19px;
position: absolute;
top: 0px;
left: 3px;
color: #49a6db;
}
Change it to (add a slash):
.edd_price_option_1762:checked:after {
content: "\2714";
font-size: 19px;
position: absolute;
top: 0px;
left: 3px;
color: #49a6db;
}
See attached screenshot:
I don't know whether this will help in any ways. But was experimenting so thought you should see this:
fiddle
Using javascript
document.getElementById('test').innerHTML = "✔"
See if it helps. I read somewhere to use HTML entity :)
some thing like
✔
Have you tried using single quotes? Don't know if it will help, but in my css I'm using content: ' \2714'; and the check mark is showing fine, except in <=IE7 where I use a graphic instead.