<input type='checkbox' name='chkbox'/>
I want to change the checkbox height and width and also background color if possible
You can look at this piece of code for starters.
It uses the before element to create a custom shape and hide the default checkbox for two states 'checked' and 'unchecked'
Also give a label for that corresponding checkbox so that clicking this custom shape will actually trigger the hidden default checkbox.
body {
font-family: 'segoe ui';
background-color: white;
padding: 10px;
}
.space {
height: 10px;
}
.checkbox * {
box-sizing: border-box;
position: relative;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.checkbox {
display: inline-block;
}
.checkbox>input {
display: none;
}
.checkbox>label {
vertical-align: top;
font-size: 18px;
padding-left: 30px;
}
.checkbox>[type="checkbox"]+label:before {
color: #777;
content: '';
position: absolute;
left: 0px;
display: inline-block;
min-height: 20px;
height: 20px;
width: 20px;
border: 2px solid #777;
font-size: 15px;
vertical-align: top;
text-align: center;
transition: all 0.2s ease-in;
content: '';
}
.checkbox.radio-square>[type="checkbox"]+label:before {
border-radius: 0px;
}
.checkbox.radio-rounded>[type="checkbox"]+label:before {
border-radius: 25%;
}
.checkbox.radio-blue>[type="checkbox"]+label:before {
border: 2px solid #ccc;
}
.checkbox>[type="checkbox"]+label:hover:before {
border-color: lightgreen;
}
.checkbox>[type="checkbox"]:checked+label:before {
width: 8px;
height: 16px;
border-top: transparent;
border-left: transparent;
border-color: green;
border-width: 4px;
transform: rotate(45deg);
top: -4px;
left: 4px;
}
<div class="checkbox">
<input id="chkTest" type="checkbox" />
<label for="chkTest">Task one</label>
<div class="space">
</div>
<input id="chkTest1" type="checkbox" />
<label for="chkTest1">Task two</label>
</div>
Related
I have an awesome font span that's functioning as my menu arrow. When the text doesn't fully cover the container the arrow floats fine off to the right, but if the text fits just right the arrow gets pushed out.
The arrow icon sits within the label, and the label sits within a nav. The arrow is not the button. The button is a checkbox hidden that also sits within the label.
nav.tag {
background: #cdcdcd;
width: 100%;
line-height: 40px;
padding: 5px 0px 5px;
border-radius: 5px 5px 5px 5px;
-webkit-touch-callout: none;
/* iOS Safari */
-webkit-user-select: none;
/* Safari */
-khtml-user-select: none;
/* Konqueror HTML */
-moz-user-select: none;
/* Old versions of Firefox */
-ms-user-select: none;
/* Internet Explorer/Edge */
user-select: none;
margin-bottom: 5px;
margin-top: 30px;
}
label.button {
line-height: 130%
}
.button {
padding-left: 20px;
}
input[type='checkbox'] {
display: none;
}
nav label {
font-size: 20px;
display: block;
cursor: pointer;
}
.button span {
float: right;
line-height: 130%;
margin-right: 20px;
margin-top: 0px;
}
nav ul label:nth-child(1) {
font-weight: bold;
font-size: 20px;
}
nav.tag ul {
background: rgb(221, 221, 221);
list-style: none;
width: 100%;
border-radius: 0px 0px 5px 5px;
padding-bottom: 5px;
display: none;
}
.bold-me {
transition: 30ms;
}
.highlight {
font-weight: bold;
color: #005DA4;
font-size: 21px;
}
[id^=btn]:checked+ul {
display: block;
}
nav.tag ul li {
line-height: 40px;
padding 8px 20px;
cursor: pointer;
margin-top: 10px;
}
nav.tag ul li:nth-child(5) {
margin-top: 0px;
}
.divider {
width: 80%;
height: 2px;
background-color: #BBBBBB;
}
.course-title {
font-size: 24px;
}
.people {
border: solid 1px #BBBBBB;
height: 32px;
width: 50px;
padding: 0px 0px 0px 20px;
font-size: 17px;
outline: none;
border: none;
transition: 100ms;
border-radius: 5px;
transform: translateY(-1.5px);
}
.people:focus {
box-shadow: 0 0 3pt 1pt cornflowerblue;
}
.radio {
display: inline-flex;
align-items: center;
cursor: pointer;
margin-right: 10px;
}
.radio__input {
display: none;
}
.radio__radio {
width: 25px;
height: 25px;
border: 3px solid rgb(103, 103, 103);
border-radius: 50%;
margin-right: 10px;
box-sizing: border-box;
padding: 2px;
transition: 150ms;
background: #f4f4f4
}
.a,
.b {
border: none;
border-radius: 5px;
font-size: 23px;
font-weight: lighter;
width: 30px;
outline: none;
cursor: pointer;
transition: 120ms;
}
.a {
padding-bottom: 2px;
}
.a:active,
.b:active {
background-color: #3382BE;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}
.radio__radio:hover {
box-shadow: 0 0 3pt 1pt cornflowerblue;
}
.radio__radio::after {
content: "";
width: 100%;
height: 100%;
display: block;
background: #3382BE;
border-radius: 50%;
transform: scale(0);
transition: transform 150ms;
}
.radio__input:checked+.radio__radio::after {
transform: scale(1);
}
.remove-course {
border: none;
background-color: transparent;
cursor: pointer;
color: #535353;
font-size: 17px;
font-weight: bold;
border-radius: 5px;
transition: 150ms;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
text-decoration: underline;
outline: none;
}
.remove-course:hover {
color: #3382BE;
outline: none;
}
#btn {
display: none;
}
.arrow {
transition: 250ms ease-out;
}
.rotate {}
.button span.rotate {
transform: rotate(-180deg);
}
.fa-user {
margin-right: 10px;
font-size: 24px;
transform: translateY(3px);
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<nav class="tag">
<label for="'+btn+'" class="button bold-me" onclick="rotate()">'+course_name+'<span class="fas fa-caret-down arrow"></span> </label><input type="checkbox" id="'+btn+'">
<ul class="menu">
<li>
<label for="" class="title course">Express Program Preference:</label>
<label for="radio1" class="radio">
<input type="radio" name="express-radio" id="radio1" class="radio__input">
<div class="radio__radio"></div>
A Must
</label>
<label for="radio2" class="radio">
<input type="radio" name="express-radio" id="radio2" class="radio__input">
<div class="radio__radio"></div>
Would Like
</label>
<label for="radio3" class="radio">
<input type="radio" name="express-radio" id="radio3" class="radio__input" checked>
<div class="radio__radio"></div>
No Preference
</label>
</li>
<li>
<div class="divider"></div>
</li>
<li> <label for="" class="course-title">Expected Party Size:</label> <i class="fas fa-user"></i><input type="number" name="" value="1" min="1" class="people" id="total"> <button onclick="minus()" class="a">-</button> <button onclick="add()" class="b">+</button> </li>
<li>
<div class="divider"></div>
</li>
<li> <button onclick="tagDelete(event)" class="remove-course">Remove Course</button> </li>
</ul>
</nav>
This is one of those rare cases where absolute positioning is useful.
label.button {
position: relative; /* <-- causes the label to act as a container */
padding-right: 20px;
}
.fa-caret-down {
position: absolute;
right: 0;
bottom: 0;
}
nav.tag {
background: #cdcdcd;
width: 100%;
line-height: 40px;
padding: 5px 0px 5px;
border-radius: 5px 5px 5px 5px;
-webkit-touch-callout: none;
/* iOS Safari */
-webkit-user-select: none;
/* Safari */
-khtml-user-select: none;
/* Konqueror HTML */
-moz-user-select: none;
/* Old versions of Firefox */
-ms-user-select: none;
/* Internet Explorer/Edge */
user-select: none;
margin-bottom: 5px;
margin-top: 30px;
}
label.button {
line-height: 130%
}
.button {
padding-left: 20px;
}
input[type='checkbox'] {
display: none;
}
nav label {
font-size: 20px;
display: block;
cursor: pointer;
}
.button span {
float: right;
line-height: 130%;
margin-right: 20px;
margin-top: 0px;
}
nav ul label:nth-child(1) {
font-weight: bold;
font-size: 20px;
}
nav.tag ul {
background: rgb(221, 221, 221);
list-style: none;
width: 100%;
border-radius: 0px 0px 5px 5px;
padding-bottom: 5px;
display: none;
}
.bold-me {
transition: 30ms;
}
.highlight {
font-weight: bold;
color: #005DA4;
font-size: 21px;
}
[id^=btn]:checked+ul {
display: block;
}
nav.tag ul li {
line-height: 40px;
padding 8px 20px;
cursor: pointer;
margin-top: 10px;
}
nav.tag ul li:nth-child(5) {
margin-top: 0px;
}
.divider {
width: 80%;
height: 2px;
background-color: #BBBBBB;
}
.course-title {
font-size: 24px;
}
.people {
border: solid 1px #BBBBBB;
height: 32px;
width: 50px;
padding: 0px 0px 0px 20px;
font-size: 17px;
outline: none;
border: none;
transition: 100ms;
border-radius: 5px;
transform: translateY(-1.5px);
}
.people:focus {
box-shadow: 0 0 3pt 1pt cornflowerblue;
}
.radio {
display: inline-flex;
align-items: center;
cursor: pointer;
margin-right: 10px;
}
.radio__input {
display: none;
}
.radio__radio {
width: 25px;
height: 25px;
border: 3px solid rgb(103, 103, 103);
border-radius: 50%;
margin-right: 10px;
box-sizing: border-box;
padding: 2px;
transition: 150ms;
background: #f4f4f4
}
.a,
.b {
border: none;
border-radius: 5px;
font-size: 23px;
font-weight: lighter;
width: 30px;
outline: none;
cursor: pointer;
transition: 120ms;
}
.a {
padding-bottom: 2px;
}
.a:active,
.b:active {
background-color: #3382BE;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}
.radio__radio:hover {
box-shadow: 0 0 3pt 1pt cornflowerblue;
}
.radio__radio::after {
content: "";
width: 100%;
height: 100%;
display: block;
background: #3382BE;
border-radius: 50%;
transform: scale(0);
transition: transform 150ms;
}
.radio__input:checked+.radio__radio::after {
transform: scale(1);
}
.remove-course {
border: none;
background-color: transparent;
cursor: pointer;
color: #535353;
font-size: 17px;
font-weight: bold;
border-radius: 5px;
transition: 150ms;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
text-decoration: underline;
outline: none;
}
.remove-course:hover {
color: #3382BE;
outline: none;
}
#btn {
display: none;
}
.arrow {
transition: 250ms ease-out;
}
.rotate {}
.button span.rotate {
transform: rotate(-180deg);
}
.fa-user {
margin-right: 10px;
font-size: 24px;
transform: translateY(3px);
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<nav class="tag">
<label for="'+btn+'" class="button bold-me" onclick="rotate()">A very long course name that's very long with many really long words that goes on and on for quite some time - it's actually rather crazy how long the label is, and someone should really look into it<span class="fas fa-caret-down arrow"></span> </label><input type="checkbox" id="'+btn+'">
<ul class="menu">
<li>
<label for="" class="title course">Express Program Preference:</label>
<label for="radio1" class="radio">
<input type="radio" name="express-radio" id="radio1" class="radio__input">
<div class="radio__radio"></div>
A Must
</label>
<label for="radio2" class="radio">
<input type="radio" name="express-radio" id="radio2" class="radio__input">
<div class="radio__radio"></div>
Would Like
</label>
<label for="radio3" class="radio">
<input type="radio" name="express-radio" id="radio3" class="radio__input" checked>
<div class="radio__radio"></div>
No Preference
</label>
</li>
<li>
<div class="divider"></div>
</li>
<li> <label for="" class="course-title">Expected Party Size:</label> <i class="fas fa-user"></i><input type="number" name="" value="1" min="1" class="people" id="total"> <button onclick="minus()" class="a">-</button> <button onclick="add()" class="b">+</button> </li>
<li>
<div class="divider"></div>
</li>
<li> <button onclick="tagDelete(event)" class="remove-course">Remove Course</button> </li>
</ul>
</nav>
I have customized my checkbox css. I have given an outline and a border to my checkbox. When i focus or click on the checkbox, the border and outline are not consistent with it. I tried giving the same border and outline to focus pseudo class, but it is not working.
Below is my HTML and CSS that i am using for the checkbox.
HTML:
<label class="form__field__input__label"><input class="form__field__input__checkbox" type="checkbox" name="World languages" value="">World languages</label>
CSS:
.form__field__input__label {
flex: 0 0 25%;
margin: 30px 0;
display: flex;
font-family: 'NotoSans';
font-size: 18px;
line-height: 26px;
color: #4e4f4f;
.form__field__input__checkbox {
width: 25px;
height: 24px;
margin-right: 15px;
position: relative;
border: solid 1px #4e4f4f;
outline: solid 0.5px $labelColor;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
&:checked::before {
content: "";
position: absolute;
width: 15px;
height: 14px;
top: 4px;
right: 4px;
background-color: #4e4f4f;
transition: all 0.3s linear;
}
&:checked:focus {
outline: solid 0.5px $labelColor;
}
}
}
I think this code could help you -
.form__field__input__label {
flex: 0 0 25%;
margin: 30px 0;
display: flex;
font-family: 'NotoSans';
font-size: 18px;
line-height: 26px;
color: #4e4f4f;
}
.form__field__input__checkbox {
width: 25px;
height: 24px;
margin-right: 15px;
position: relative;
border: solid 1px #4e4f4f;
outline: solid 0.5px $labelColor;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
}
.form__field__input__checkbox:checked::before {
content: "";
position: absolute;
width: 15px;
height: 14px;
top: 4px;
right: 4px;
background-color: #4e4f4f;
transition: all 0.3s linear;
}
.form__field__input__checkbox:checked:focus {
outline: solid 0.5px $labelColor;
}
<label class="form__field__input__label"><input class="form__field__input__checkbox" type="checkbox" name="World languages" value="">World languages</label>
I need to make this Range slider responsive. Text is getting overlapped when i start using in mobile version. Please help me to achieve this.
I have tried to add it in Table responsive and adding some responsive divs but still it didn't workout.
It would be great if someone help me to find out the way to make it responsive. You can see executable code in
#import url(https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet);
#import url("https://fonts.googleapis.com/css?family=Dancing+Script");
.label-container {
margin-top: 0.5rem;
-webkit-flex-basis: 100%;
display: -webkit-flex;
-webkit-flex-wrap: nowrap;
-webkit-justify-content: space-between;
margin-bottom: 50px;
}
.label-slider {
color: #3949ab;
font-size: 14px;
font-weight: 700;
text-align: center;
-webkit-tap-highlight-color: transparent;
cursor: pointer;
}
.label-slider:nth-child(1) {
padding-left: 0px;
}
.label-slider:nth-child(2) {
padding-left: 18px;
}
.label-slider:nth-child(3) {
padding-left: 34px;
}
.label-slider:nth-child(4) {
padding-left: 32px;
}
.label-slider:nth-child(5) {
padding-left: 32px;
}
.slider-container {
width: 100%;
margin-top: 5px;
}
.slider {
-webkit-appearance: none;
-moz-appearance: none;
width: 100%;
height: 10px;
border-radius: 5px;
background: #dde5ff;
outline: none;
opacity: 0.7;
-webkit-transition: 0.2s;
transition: opacity 0.2s;
}
input[type="range"],
input[type="range"]::-moz-range-track {
-webkit-appearance: none;
-moz-appearance: none;
width: 100%;
border-radius: 5px;
background: #dde5ff;
outline: none;
transition: opacity 0.2s;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #2b8aeb;
cursor: pointer;
outline: none;
}
input[type="range"]::-moz-range-thumb {
-moz-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #1492ea;
cursor: pointer;
outline: none;
z-index: 10;
}
input[type="range"]:focus {
outline: none;
}
<body>
<p class="title">Range Sliders</p>
<h4>Range Slider without steps</h4>
<div class="slider-container">
<input type="range" min="0" max="4" class="slider">
</div>
<div class="label-container">
<div class="label-slider">None</div>
<div class="label-slider">1</div>
<div class="label-slider">2</div>
<div class="label-slider">3</div>
<div class="label-slider">4+</div>
</div>
</body>
Just replace width: 600px by max-width:600px; in container.
For the font-size, I would recommand you to set font size based in rem. and set breakpoints font-size on your html element to size as you wish. as this subject: Rem not compatible with media queries?
Ad I will also recommand you to remove container padding-left and right when you under a certain width of screen, this way, the scale will stay well align with your input.
Edit
To fix the the container label, I set them with position absolute.
First step add position relative on container:
.label-container{
position:relative;
}
Then add position: absolute on labels:
.label-slider{
position: absolute;
}
And finaly just Adjust correctly with absolute as follow:
.label-slider:nth-child(1) {
left:0;
}
.label-slider:nth-child(2) {
left:25%;
transform: translateX(-25%);
margin-left: 1%;
}
.label-slider:nth-child(3) {
left:50%;
transform: translateX(-50%);
margin-left: .5%;
}
.label-slider:nth-child(4) {
right: 25%;
transform: translateX(25%);
margin-left: 1%;
}
.label-slider:nth-child(5) {
right:0;
}
DEMO FULL
#import url(https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet);
#import url("https://fonts.googleapis.com/css?family=Dancing+Script");
body {
font-family: "Catamaran", sans-serif;
background: #2b8aeb;
}
.container {
font-family: "Catamaran", sans-serif;
max-width: 600px;
margin: 30px auto 0;
display: block;
background: #fff;
padding: 10px 50px 50px;
border-radius: 4px;
box-shadow 0 6px 16px rgba(0,0,0,0.15)
}
.title {
text-align: center;
font-family: "Dancing Script", cursive;
color: #3949ab;
font-size: 35px;
}
.label-container {
margin-top: 0.5rem;
-webkit-flex-basis: 100%;
display: -webkit-flex;
-webkit-flex-wrap: nowrap;
-webkit-justify-content: space-between;
margin-bottom: 50px;
position : relative;
}
.label-slider {
color: #3949ab;
font-size: 14px;
font-weight: 700;
text-align: center;
-webkit-tap-highlight-color: transparent;
cursor: pointer;
position: absolute;
}
.label-slider:nth-child(1) {
left:0;
}
.label-slider:nth-child(2) {
left:25%;
transform: translateX(-25%);
margin-left: 1%;
}
.label-slider:nth-child(3) {
left:50%;
transform: translateX(-50%);
margin-left: .5%;
}
.label-slider:nth-child(4) {
right: 25%;
transform: translateX(25%);
margin-left: 1%;
}
.label-slider:nth-child(5) {
right:0;
}
.slider-container {
width: 100%;
margin-top: 5px;
}
.slider {
-webkit-appearance: none;
-moz-appearance: none;
width: 100%;
height: 10px;
border-radius: 5px;
background: #dde5ff;
outline: none;
opacity: 0.7;
-webkit-transition: 0.2s;
transition: opacity 0.2s;
}
input[type="range"],
input[type="range"]::-moz-range-track {
-webkit-appearance: none;
-moz-appearance: none;
width: 100%;
border-radius: 5px;
background: #dde5ff;
outline: none;
transition: opacity 0.2s;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #2b8aeb;
cursor: pointer;
outline: none;
}
input[type="range"]::-moz-range-thumb {
-moz-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #1492ea;
cursor: pointer;
outline: none;
z-index: 10;
}
input[type="range"]:focus {
outline: none;
}
.ticks {
font-family: "Catamaran", sans-serif;
color: #3949ab;
font-size: 14px;
font-weight: 700;
display: flex;
justify-content: space-between;
height: 6px;
margin: 0 10px 0 15px;
counter-reset: count -1;
}
.ticks > div {
height: 100%;
width: 1px;
background: silver;
counter-increment: count 1;
}
.ticks > div:nth-child(5n - 4) {
height: 200%;
}
.ticks > div:nth-child(5n - 4)::before {
display: block;
content: counter(count,decimal);
transform: translate(-50%, 100%);
text-align: center;
width: 16px;
}
<body>
<div class="container">
<p class="title">Range Sliders</p>
<h4>Range Slider without steps</h4>
<div class="slider-container">
<input type="range" min="0" max="4" class="slider">
</div>
<div class="label-container">
<div class="label-slider">None</div>
<div class="label-slider">1</div>
<div class="label-slider">2</div>
<div class="label-slider">3</div>
<div class="label-slider">4+</div>
</div>
</div>
</body>
I am trying to create a design from a graphic artists and i have successfully created the button that acts like a checkbox, however i cant seem to figure out the CSS to mimic the design. Its grey but on hover/click(checked) it changes color. I'm using bootstrap and fontawesome to try and achieve this.
IMG of functionality im trying to replicate:
https://jsfiddle.net/nojil/Lskdcu6r/31/
#canvasBranch-ck-button {
margin: 4px;
background-color: #fff;
border-radius: 4px;
border: 1px solid #D0D0D0;
overflow: auto;
float: left;
width: 150px;
}
#canvasBranch-ck-button:hover {
background: #fff;
color: #ff4c00;
border-color: #ff4c00;
cursor: pointer;
}
#canvasBranch-ck-button label {
float: left;
width: 100%;
}
#canvasBranch-ck-button label span {
text-align: center;
padding: 3px 0px;
display: block;
}
#canvasBranch-ck-button label span.iconSpan {
background-color: #D0D0D0;
color: #fff;
}
#canvasBranch-ck-button label input {
position: absolute;
top: -20px;
}
#canvasBranch-ck-button input:checked+span.textSpan {
color: #ff4c00 !important;
}
#canvasBranch-ck-button input:checked+span.iconSpan {
background-color: #ff4c00;
}
<div id="canvasBranch-ck-button">
<label class="d-flex mb-0">
<input type="checkbox" value="canvasBranch">
<span class="flex-fill align-items-center iconSpan"><i class="fas fa-angle-left"></i></span>
<span class="align-items-center flex-fill textSpan">Canvas Branch</span>
</label>
</div>
Given that you've shown an attempt, I figured I could throw you a bone here and give you a bit of an idea of how this might be implemented.
The issue you've run into, that I've explained in my comments, is that you're trying to style a parent (the <div>) based on the status (checked/unchecked) of a child, which cannot be done in CSS.
Given the use of ::before, you could also implement icon-specific styling. You'll notice how I implemented them using the .money and .question class, and the only declaration necessary would be content: 'x'. You can do this with Font-Awesome too.
Consider something like this instead. Of course, you'll need to update the fonts and whatnot.
body {
font-family: arial;
background-color: #f6f6f6;
}
.hidden {
display: none;
}
label {
display: block;
border: 1px solid transparent;
display: flex;
max-width: 170px;
border-radius: 6px;
overflow: hidden;
background-color: #eee;
align-items: center;
cursor: pointer;
margin: 5px;
}
label::before {
width: 35px;
padding: 10px 0;
display: block;
background-color: #ccc;
color: white;
font-size: 18px;
content: '!';
text-align: center;
}
label.money::before {
content: '$';
}
label.question::before {
content: '?';
}
label>.text {
display: block;
flex-grow: 1;
text-align: center;
height: 100%;
padding-top: 2px;
font-size: 13px;
color: #333;
}
label:hover,
input:checked+label {
border: 1px solid #ff4c00;
}
label:hover>.text,
input:checked+label>.text {
color: #ff4c00;
}
input:checked+label {
background-color: white;
}
input:checked+label::before {
background-color: #ff4c00;
}
<input class="hidden" id="chk1" type="checkbox">
<label class="" for="chk1">
<span class="text">GENERIC</span>
</label>
<input class="hidden" id="chk2" type="checkbox">
<label class="money" for="chk2">
<span class="text">MONEY</span>
</label>
<input class="hidden" id="chk3" type="checkbox">
<label class="question" for="chk3">
<span class="text">QUESTION</span>
</label>
As #TylerRopper mention on the comment You cannot style a parent based on a child but you can always fake it, here it is:
<div id="canvasBranch-ck-button">
<label class="d-flex mb-0">
<input type="checkbox" value="canvasBranch">
<span class="flex-fill align-items-center iconSpan"><i class="fas fa-angle-left"></i></span>
<span class="align-items-center flex-fill textSpan">Canvas Branch</span>
<div class="fakeborder">
</div>
</label>
Css
#canvasBranch-ck-button {
margin: 4px;
background-color: #fff;
border-radius: 4px;
border: 1px solid #D0D0D0;
overflow: auto;
float: left;
width: 150px;
}
#fakeborder{
width:150px;
}
#canvasBranch-ck-button:hover {
background: #fff;
color: #ff4c00;
border-color: #ff4c00;
cursor: pointer;
}
#canvasBranch-ck-button label {
float: left;
width: 100%;
}
#canvasBranch-ck-button label span {
text-align: center;
padding: 3px 0px;
display: block;
}
#canvasBranch-ck-button label span.iconSpan {
background-color: #D0D0D0;
color: #fff;
}
#canvasBranch-ck-button label input {
position: absolute;
top: -20px;
}
#canvasBranch-ck-button input:checked ~ span.textSpan {
color: #ff4c00 !important;
}
#canvasBranch-ck-button input:checked ~ span.iconSpan {
background-color: #ff4c00;
}
#canvasBranch-ck-button input:checked ~ .fakeborder {
border: 2px solid #ff4c00;
width:151px;
height: 32px;
margin:-1px;
border-radius: 4px;
position:absolute;
}
And here is the fiddle
You can use this as a starting point and customize to your likings.
cb1.addEventListener('click', function() {
console.log(cb1.checked)
})
.cb-btn {
display: none;
}
.cb-btn + label {
border: 1px solid #999;
border-radius: 5px;
cursor: pointer;
padding: 5px 0.5em 5px 2.5em;
position: relative;
}
.cb-btn:not(:checked + label):hover {
border-color: #a00;
color: #a00;
transition: all .2s ease-in-out;
}
.cb-btn + label::before {
background-color: #999;
border-radius: 5px 0 0 5px;
bottom: 0;
content: "$ ";
display: block;
left: 0;
line-height: 1.9em;
position: absolute;
text-align: center;
top: 0;
transition: all .2s ease-in-out;
width: 2em;
}
.cb-btn:not(:checked) + label:hover::before {
background-color: #a00;
color: #fff;
}
.cb-btn:checked + label {
border: 1px solid green;
border-radius: 5px;
color: green;
cursor: pointer;
padding: 5px 0.5em 5px 2.5em;
position: relative;
}
.cb-btn:checked + label::before {
background-color: green;
color: #fff;
}
<input type="checkbox" value="canvasBranch" id="cb1" class="cb-btn">
<label class="d-flex mb-0" for="cb1">Label Text</label>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
This is the sample http://jsfiddle.net/TX8fs/1/
I tried
display:block;float:left;
But the urgent input checkbox will overlap the 2 input infront of it. Any solution to fix this? I want to display the urgent input checkbox beside the label.
Something like this? jsfiddle
Note: only switched order of HTML elements inside div, and added "float: left;" to **
.select-style{
display: inline;
}
.onoffswitch {
position: relative; width: 136px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
float: left; /* ** added line ** */
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 0px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 19px; padding: 0; line-height: 15px;
font-size: 12px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
border: 2px solid transparent;
}
.onoffswitch-inner:before {
content: "URGENT";
padding-left: 10px;
background-color: #FF0000; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "URGENT";
padding-right: 10px;
background-color: #EEEEEE; color: #000000;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 12px; margin: 0px;
background: #A1A1A1;
position: absolute; top: 0; bottom: 0;
right: 124px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
background-color: #A1A1A1;
}
<!--Text box -->
<input data-toggle="collapse" data-target="#b" type="checkbox">
<label class="label-supplier"> abc </label>
<!-- dropdown menu -->
<div class="select-style">
<div class="onoffswitch">
<label class="onoffswitch-label" for="#a">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
<!-- Switch order of checkbox and switch-->
<input type="checkbox" class="onoffswitch-checkbox btn-urgent" id="#a">
</div>
</div>
The easiest solution is to simply make your .select-style an inline-block instead of an inline element, as can be seen here.
.select-style {
display: inline-block;
}
.onoffswitch {
position: relative;
width: 136px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 0px;
}
.onoffswitch-inner {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before,
.onoffswitch-inner:after {
display: block;
float: left;
width: 50%;
height: 19px;
padding: 0;
line-height: 15px;
font-size: 12px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
border: 2px solid transparent;
}
.onoffswitch-inner:before {
content: "URGENT";
padding-left: 10px;
background-color: #FF0000;
color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "URGENT";
padding-right: 10px;
background-color: #EEEEEE;
color: #000000;
text-align: right;
}
.onoffswitch-switch {
display: block;
width: 12px;
margin: 0px;
background: #A1A1A1;
position: absolute;
top: 0;
bottom: 0;
right: 124px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-switch {
right: 0px;
background-color: #A1A1A1;
}
<!--Text box -->
<input data-toggle="collapse" data-target="#b" type="checkbox">
<label class="label-supplier"> abc </label>
<!-- dropdown menu -->
<div class="select-style">
<div class="onoffswitch">
<input type="checkbox" class="onoffswitch-checkbox btn-urgent" id="#a">
<label class="onoffswitch-label" for="#a">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
However, if you additionally want to ensure that all three elements are aligned vertically, you'll need to also add vertical-align: middle to all three elements:
input, input + label, .select-style {
vertical-align: middle;
}
Which results in the following:
.select-style {
display: inline-block;
}
.onoffswitch {
position: relative;
width: 136px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 0px;
}
.onoffswitch-inner {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before,
.onoffswitch-inner:after {
display: block;
float: left;
width: 50%;
height: 19px;
padding: 0;
line-height: 15px;
font-size: 12px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
border: 2px solid transparent;
}
.onoffswitch-inner:before {
content: "URGENT";
padding-left: 10px;
background-color: #FF0000;
color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "URGENT";
padding-right: 10px;
background-color: #EEEEEE;
color: #000000;
text-align: right;
}
.onoffswitch-switch {
display: block;
width: 12px;
margin: 0px;
background: #A1A1A1;
position: absolute;
top: 0;
bottom: 0;
right: 124px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-switch {
right: 0px;
background-color: #A1A1A1;
}
input, input + label, .select-style {
vertical-align: middle;
}
<!--Text box -->
<input data-toggle="collapse" data-target="#b" type="checkbox">
<label class="label-supplier"> abc </label>
<!-- dropdown menu -->
<div class="select-style">
<div class="onoffswitch">
<input type="checkbox" class="onoffswitch-checkbox btn-urgent" id="#a">
<label class="onoffswitch-label" for="#a">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
Hope this helps! :)