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>
Related
I've created this simple Login form for a uni project and for some reason the box around the text field is still showing, I want it to be invisible.
How the form works is; when a user clicks on either field, the placeholder lifts up and they type below it (refer to screenshot)
For some reason, however, the text box is still there.
Any help would be greatly appreciated.
.center {
position:fixed;
top: 40%;
left: 70%;
transform: translate(-50%, -50%);
width: 720px;
height: 350px;
background: linear-gradient(180deg, white, silver );
size: 100%;
border-style: solid;
border-color: black;
border-width: 1px;
}
.center h1{
text-align: center;
padding: 0 0 20px 0;
border-bottom: 1px solid silver;
}
.center form {
padding: 0 40px;
}
form .txt_field {
position: relative;
border-bottom: 2px solid #adadad;
margin: 30px 0;
}
.txt-field input {
width: 100%;
padding: 0 5px;
height: 40px;
font-size: 16px;
border: none;
background: none;
outline: none;
}
.no-outlin:focus{
outline: none;
}
.txt_field label{
position: absolute;
top: 50%;
left: 5px;
color: #adadad;
transform: translateY(-50%);
font-size: 16px;
pointer-events: none;
transition: .7s;
border: none;
}
.txt_field span::before{
content: '';
position: absolute;
top: 40px;
left: 0;
width: 0%;
height: 2px;
background: #2691d9;
transition: .7s;
}
.txt_field input:focus ~ label,
.txt_field input:valid ~ label {
top: -5px;
color: #2691d9;
}
.txt_field input:focus ~ span::before,
.txt_field input:valid ~ span::before {
width: 100%;
}
.pass {
margin: -5px 0 20px 5px;
color: #a6a6a6;
cursor: pointer;
}
.pass:hover {
text-decoration: underline;
}
input[type="submit"]{
width: 100%;
height: 50px;
border: 1px solid;
background: #2691d9;
border-radius: 25px;
font-size: 18px;
color: #e9f4fb;
font-weight: 700;
cursor: pointer;
outline: none;
}
input[type="submit"]:hover{
border-color: #2691d9;
transition: .5s;
}
.signup_link {
margin: 30px;
text-align: center;
font-size: 16px;
color: #666666;
}
.signup_link a{
color: #2691d9;
text-decoration: none;
}
.signup_link a:hover{
color: #2691d9;
text-decoration: underline;
}
<head>
</head>
<body class="Body">
<div class="center">
<h1> Login </h1>
<form method="post" class="Box">
<div class="txt_field">
<input type="text" required>
<span></span>
<label>Username</label>
</div>
<div class="txt_field">
<input type="password" required>
<span></span>
<label>Password</label>
</div>
<div class="pass"> Forgotten Password? </div>
<input type="submit" value="Login">
<div class="signup_link">
Not a Member? <a class="nav-item-nav-link" routerLink="/register">Create an Account!</a>
</div>
</form>
</div>
Click here for sceenshot
There's a typo in your CSS
Change the txt-field in your CSS to txt_field
This is your code:
.center {
position: fixed;
top: 40%;
left: 70%;
transform: translate(-50%, -50%);
width: 720px;
height: 350px;
background: linear-gradient(180deg, white, silver);
size: 100%;
border-style: solid;
border-color: black;
border-width: 1px;
}
.center h1 {
text-align: center;
padding: 0 0 20px 0;
border-bottom: 1px solid silver;
}
.center form {
padding: 0 40px;
}
form .txt_field {
position: relative;
border-bottom: 2px solid #adadad;
margin: 30px 0;
}
.txt_field input {
width: 100%;
padding: 0 5px;
height: 40px;
font-size: 16px;
border: none;
background: none;
outline: none;
}
.no-outlin:focus {
outline: none;
}
.txt_field label {
position: absolute;
top: 50%;
left: 5px;
color: #adadad;
transform: translateY(-50%);
font-size: 16px;
pointer-events: none;
transition: .7s;
border: none;
}
.txt_field span::before {
content: '';
position: absolute;
top: 40px;
left: 0;
width: 0%;
height: 2px;
background: #2691d9;
transition: .7s;
}
.txt_field input:focus~label,
.txt_field input:valid~label {
top: -5px;
color: #2691d9;
}
.txt_field input:focus~span::before,
.txt_field input:valid~span::before {
width: 100%;
}
.pass {
margin: -5px 0 20px 5px;
color: #a6a6a6;
cursor: pointer;
}
.pass:hover {
text-decoration: underline;
}
input[type="submit"] {
width: 100%;
height: 50px;
border: 1px solid;
background: #2691d9;
border-radius: 25px;
font-size: 18px;
color: #e9f4fb;
font-weight: 700;
cursor: pointer;
outline: none;
}
input[type="submit"]:hover {
border-color: #2691d9;
transition: .5s;
}
.signup_link {
margin: 30px;
text-align: center;
font-size: 16px;
color: #666666;
}
.signup_link a {
color: #2691d9;
text-decoration: none;
}
.signup_link a:hover {
color: #2691d9;
text-decoration: underline;
}
<head>
</head>
<body class="Body">
<div class="center">
<h1> Login </h1>
<form method="post" class="Box">
<div class="txt_field">
<input type="text" required>
<span></span>
<label>Username</label>
</div>
<div class="txt_field">
<input type="password" required>
<span></span>
<label>Password</label>
</div>
<div class="pass"> Forgotten Password? </div>
<input type="submit" value="Login">
<div class="signup_link">
Not a Member? <a class="nav-item-nav-link" routerLink="/register">Create an Account!</a>
</div>
</form>
</div>
target the input not thee div
.center {
position: fixed;
top: 40%;
left: 70%;
transform: translate(-50%, -50%);
width: 720px;
height: 350px;
background: linear-gradient(180deg, white, silver);
size: 100%;
border-style: solid;
border-color: black;
border-width: 1px;
}
.center h1 {
text-align: center;
padding: 0 0 20px 0;
border-bottom: 1px solid silver;
}
.center form {
padding: 0 40px;
}
form .txt_field {
position: relative;
border-bottom: 2px solid #adadad;
margin: 30px 0;
}
.txt_field input:focus {
outline: none;
}
.no-outlin:focus {
outline: none;
}
.txt_field label {
position: absolute;
top: 50%;
left: 5px;
color: #adadad;
transform: translateY(-50%);
font-size: 16px;
pointer-events: none;
transition: .7s;
border: none;
}
.txt_field span::before {
content: '';
position: absolute;
top: 40px;
left: 0;
width: 0%;
height: 2px;
background: #2691d9;
transition: .7s;
}
.txt_field input:focus~label,
.txt_field input:valid~label {
top: -5px;
color: #2691d9;
}
.txt_field input:focus~span::before,
.txt_field input:valid~span::before {
width: 100%;
}
.pass {
margin: -5px 0 20px 5px;
color: #a6a6a6;
cursor: pointer;
}
.pass:hover {
text-decoration: underline;
}
input[type="submit"] {
width: 100%;
height: 50px;
border: 1px solid;
background: #2691d9;
border-radius: 25px;
font-size: 18px;
color: #e9f4fb;
font-weight: 700;
cursor: pointer;
outline: none;
}
input[type="submit"]:hover {
border-color: #2691d9;
transition: .5s;
}
.signup_link {
margin: 30px;
text-align: center;
font-size: 16px;
color: #666666;
}
.signup_link a {
color: #2691d9;
text-decoration: none;
}
.signup_link a:hover {
color: #2691d9;
text-decoration: underline;
}
<head>
</head>
<body class="Body">
<div class="center">
<h1> Login </h1>
<form method="post" class="Box">
<div class="txt_field">
<input type="text" required>
<span></span>
<label>Username</label>
</div>
<div class="txt_field">
<input type="password" required>
<span></span>
<label>Password</label>
</div>
<div class="pass"> Forgotten Password? </div>
<input type="submit" value="Login">
<div class="signup_link">
Not a Member? <a class="nav-item-nav-link" routerLink="/register">Create an Account!</a>
</div>
</form>
</div>
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>
<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>
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! :)
I'm trying to make text + button on same line in bootstrap from but doesn't work. It's just doesn't want to move.
This is what I have so far
.onoffswitch {
position: relative; width: 90px;
-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: 20px;
}
.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: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #34A7C1; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 56px;
border: 2px solid #999999; border-radius: 20px;
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;
}
<div class="form-group">
<div class="col-md-12">
<div class="col-md-8"> Switch mode from here: </div>
<div class="col-md-4">
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
</div>
</div>
I want this ON / OFF switcher to go up next to Switch mode from here:. I've played with col-*, rows etc..
I have made some direct changes in your divs.
you can change as per your need.
.onoffswitch {
position: relative; width: 90px;
-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: 20px;
}
.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: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #34A7C1; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 56px;
border: 2px solid #999999; border-radius: 20px;
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;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="form-group">
<div class="col-md-12 col-xs-12">
<div class="col-md-8 col-xs-5" style="text-alignment:center;margin-top:6px;"> Switch mode from here: </div>
<div class="col-md-4 col-xs-2 " style="text-alignment:left;margin-left:-50px;">
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
</div>
</div>
Used col-xs-* for small view:
.onoffswitch {
position: relative; width: 90px;
-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: 20px;
}
.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: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #34A7C1; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 56px;
border: 2px solid #999999; border-radius: 20px;
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;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
<div class="col-md-12">
<div class="col-xs-4 col-md-4"> Switch mode from here: </div>
<div class="col-xs-4 col-md-4">
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
</div>
</div>
Make sure, you also add bootstrap column classes for all large screen sizes.
.onoffswitch {
position: relative;
width: 90px;
-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: 20px;
}
.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: 30px;
padding: 0;
line-height: 30px;
font-size: 14px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #34A7C1;
color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE;
color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block;
width: 18px;
margin: 6px;
background: #FFFFFF;
position: absolute;
top: 0;
bottom: 0;
right: 56px;
border: 2px solid #999999;
border-radius: 20px;
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;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-group">
<div class="col-md-12 col-lg-12 col-xs-12">
<div class="col-md-8 col-lg-8 col-xs-8">Switch mode from here:</div>
<div class="col-md-4 col-lg-4 col-xs-4">
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
</div>
</div>