I'm using the :focus property on an input so that when I click on it an effect occurs. However, even when I don't click on it, all the inputs have had the style contained within :focus applied as soon as I load the page.
.input-container {
position: relative;
}
.form {
background-color: white;
font-size: 16px;
overflow: hidden;
color: black;
border-radius: 10px;
width: 100%;
position: relative;
height: 100%;
padding-left: 7rem;
padding-right: 7rem;
padding-top: 5rem;
}
.form input {
outline: none;
position: relative;
margin: 0 auto;
width: 100%;
color: #595f6e;
padding-top: 30px;
border: none;
}
.form input:focus+.label-name .content-name,
.form input:valid+.label-name .content-name {
transform: translateY(-150%);
color: blue;
font-size: 14px;
}
.form input:focus+.label-name::after,
.form input:valid+.label-name::after {
transform: translateX(0%);
}
.form label {
position: absolute;
pointer-events: none;
bottom: 0px;
left: 0px;
width: 100%;
border-bottom: 2px solid black;
}
.form label::after {
content: "";
position: absolute;
left: 0px;
height: 100%;
width: 100%;
border-bottom: 3px solid blue;
transform: translateX(-100%);
transition: transform 0.3s ease;
}
.content-name {
position: absolute;
bottom: 5px;
left: 0px;
transition: all 0.3 ease;
}
<div class="form">
<div class="input-container u-margin-bottom-medium">
<input type="text" name="name" autocomplete="off">
<label for="name" class="label-name">
<span class="content-name">Name</span>
</label>
</div>
<div class="input-container u-margin-bottom-medium">
<input type="text" name="name" autocomplete="off">
<label for="name" class="label-name">
<span class="content-name">Email</span>
</label>
</div>
<div class="input-container u-margin-bottom-medium">
<input type="text" name="name" autocomplete="off">
<label for="name" class="label-name">
<span class="content-name">Message</span>
</label>
</div>
</div>
Does anyone know why this might be happening? Any help or suggestions are appreciated!
Since you need to test if there is text in the input, but want to wait until it's "valid" (this does not check to see if the actual data is valid, but rather that there is text). You can set the required attribute on the input fields. Technically, if there is no text in the input field, the field isn't "valid" until there is.
.input-container {
position: relative;
}
.form {
background-color: white;
font-size: 16px;
overflow: hidden;
color: black;
border-radius: 10px;
width: 100%;
position: relative;
height: 100%;
padding-left: 7rem;
padding-right: 7rem;
padding-top: 5rem;
}
.form input {
outline: none;
position: relative;
margin: 0 auto;
width: 100%;
color: #595f6e;
padding-top: 30px;
border: none;
}
.form input:focus+.label-name .content-name,
.form input:valid+.label-name .content-name {
transform: translateY(-150%);
color: blue;
font-size: 14px;
}
.form input:focus+.label-name::after,
.form input:valid+.label-name::after {
transform: translateX(0%);
}
.form label {
position: absolute;
pointer-events: none;
bottom: 0px;
left: 0px;
width: 100%;
border-bottom: 2px solid black;
}
.form label::after {
content: "";
position: absolute;
left: 0px;
height: 100%;
width: 100%;
border-bottom: 3px solid blue;
transform: translateX(-100%);
transition: transform 0.3s ease;
}
.content-name {
position: absolute;
bottom: 5px;
left: 0px;
transition: all 0.3 ease;
}
<div class="form">
<div class="input-container u-margin-bottom-medium">
<input type="text" name="name" autocomplete="off" required>
<label for="name" class="label-name">
<span class="content-name">Name</span>
</label>
</div>
<div class="input-container u-margin-bottom-medium">
<input type="text" name="name" autocomplete="off" required>
<label for="name" class="label-name">
<span class="content-name">Email</span>
</label>
</div>
<div class="input-container u-margin-bottom-medium">
<input type="text" name="name" autocomplete="off" required>
<label for="name" class="label-name">
<span class="content-name">Message</span>
</label>
</div>
</div>
Related
I want to change the style of the toggle-button like this.
This is my sample code:
<div class="form-group has-feedback">
<input id="wffm302ebacf2b634d59b0dc1e81e451bc8d_Sections_0__Fields_6__Id" name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Id" type="hidden" value="{D7AB5D2E-444F-49C7-91E4-564496D7C8A2}">
<div>
<input data-val="true" data-val-required="The Value field is required." id="wffm302ebacf2b634d59b0dc1e81e451bc8d_Sections_0__Fields_6__Value" name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="checkbox" value="true" autocomplete="off" style="display: none;">
<span class="button-checkbox bootstrap-checkbox">
<button type="button" class="btn clearfix custom-btn">
<span class="icon fa fa-check theme-text" style="display:none;"></span>
<span class="icon fa fa-check-square"></span>
<span class="icon cb-icon-check-indeterminate" style="display:none;"></span>
</button>
</span>
<label class="switch">
<input name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="checkbox" value="false">
<span class="slider round"></span>
</label>
</div>
<span class="field-validation-valid help-block" data-valmsg-for="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" data-valmsg-replace="true"></span>
</div>
Jsfiddle example
I tried few CSS but it is not exactly what I want. I tried:
.switchbtn:before {
position: absolute;
content: "";
height: 32px;
width: 26px;
background-color: black;
-webkit-transition: .4s;
transition: .4s;
}
You are on the right track. You can use the :before and :after pseudo CSS selectors to modify the look and feel of the toggle button. Since :before is already used to create the circular toggle, I have used :after to add the text. Obviously, there are more ways to do this, and the below is a just a quick way to show you how to achieve this.
Note that you will have to modify the pseudo selectors for both the states (normal and checked) as you want different colors.
Check the code snippet below and use that as a starting point to modify/tweak styles as per your need.
Hope this helps.
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.switchbtn {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
border: 2px solid #bbb;
-webkit-transition: .4s;
transition: .4s;
}
.switchbtn:before {
position: absolute;
content: "";
height: 34px;
width: 34px;
left: -2px;
top: -2px;
background-color: black;
-webkit-transition: .4s;
transition: .4s;
}
.switchbtn:after {
position: absolute;
content: "OFF";
right: 3px;
top: 10px;
font-size: 9px;
font-family: 'Arial';
-webkit-transition: .4s;
transition: .4s;
}
input:checked+.switchbtn {
background-color: white;
border: 2px solid #2196F3;
}
input:focus+.switchbtn {
box-shadow: 0 0 1px #2196F3;
}
input:checked+.switchbtn:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
background-color: #2196F3;
}
input:checked+.switchbtn:after {
position: absolute;
content: "ON";
left: 7px;
top: 10px;
font-size: 9px;
font-family: 'Arial';
-webkit-transition: .4s;
transition: .4s;
}
/* Rounded sliders */
.switchbtn {
border-radius: 34px;
}
.switchbtn:before {
border-radius: 50%;
}
.switch button {
display: none;
}
<label class="switch">
<input class="switchbtn" data-val="true" data-val-required="The Value field is required." id="wffm302ebacf2b634d59b0dc1e81e451bc8d_Sections_0__Fields_6__Value" name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="checkbox" value="true" autocomplete="off" style="display: none;" aria-invalid="false" aria-describedby="wffm302ebacf2b634d59b0dc1e81e451bc8d\.Sections\[0\]\.Fields\[6\]\.Value-error wffm302ebacf2b634d59b0dc1e81e451bc8d\.Sections\[0\]\.Fields\[6\]\.Value-error">
<span class="button-checkbox bootstrap-checkbox switchbtn">
<button type="button" class="btn clearfix custom-btn">
<span class="icon fa fa-check theme-text" style="display: none;"></span>
<span class="icon fa fa-check-square" style="display: inline;"></span>
<span class="icon cb-icon-check-indeterminate" style="display:none;"></span>
</button></span><input name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="hidden" value="false">
</label>
Hope this helps.
I am trying to remove spacing between elements stacked on each other.
This is what i have:
input[type="text"] {
width: 40%;
height: 30px;
border-radius: 29px;
border-style: none;
padding-right: 100px;
padding-left: 30px;
border-width: 0;
}
input[type="submit"] {
margin-left: -100px;
height: 30px;
width: 100px;
border-width: 0;
border-radius: 29px;
background: blue;
color: white;
-webkit-appearance: none;
}
body {
background-color: black;
}
<br/>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" placeholder="Enter your email"><input type="submit">
</form>
I have tried top:0; and bottom:0; but it does not seem to solve my problem in this example.
Remove padding-top and padding-bottom on input[type="text"]
padding-top: 0px;
padding-bottom: 0px;
input[type="text"] {
padding-top: 0px;
padding-bottom: 0px;
width: 40%;
height:30px;
border-radius: 29px;
border-style:none;
padding-right:100px;
padding-left:30px;
border-width: 0;
}
input[type="submit"] {
margin-left: -100px;
height:30px;
width: 100px;
border-width: 0;
border-radius: 29px;
background: blue;
color: white;
-webkit-appearance: none;
}
body {
background-color: black;
}
<br/>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" placeholder="Enter your email"><input type="submit">
</form>
Remove the top bottom padding of input[type="text"].
input[type="text"] {
width: 40%;
height: 30px;
border-radius: 29px;
border-style: none;
padding-right: 100px;
padding-left: 30px;
padding-top: 0;
padding-bottom: 0;
}
I removed the height property from both elements and added it to the container, the form. Then added display: flex to the form.
form {
height: 30px;
display: flex;
}
input[type="text"] {
width: 40%;
border-radius: 29px;
border-style: none;
padding-right: 100px;
padding-left: 30px;
border-width: 0;
}
input[type="submit"] {
margin-left: -100px;
width: 100px;
border-width: 0;
border-radius: 29px;
background: blue;
color: white;
-webkit-appearance: none;
}
body {
background-color: black;
}
<br/>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" placeholder="Enter your email"><input type="submit">
</form>
I want to display radio buttons as tabs. Following this codepen, I've attempted this in my project. But when I click on pseudo tab, nothing happens. It doesn't get checked.
How can I achieve the effect?
input.tgl-radio-tab-child {
position: absolute;
left: -99999em;
top: -99999em;
opacity: 1;
z-index: 1;
}
input.tgl-radio-tab-child+label {
cursor: pointer;
float: left;
border: 1px solid #aaa;
margin-right: -1px;
padding: .5em 1em;
position: relative;
}
input.tgl-radio-tab-child+label:hover {
background-color: #eee;
}
[type=radio]:checked+label {
background-color: #c30;
z-index: 1;
}
<label for="abc">ABC<span style="color: red;">*</span></label>
<div class="form-check">
<div class="tgl-radio-tabs">
<input type="radio" class="form-check-input tgl-radio-tab-child" name="abcorigin"><label class="radio-inline">ABCDEFGHIJKL</label>
<input type="radio" class="form-check-input tgl-radio-tab-child" name="abcorigin"><label class="radio-inline">MNOPQRSTUVWXYZ</label>
</div>
</div>
You need to bind your labels to your inputs via the for attribute which should reference the respective input's ID:
input.tgl-radio-tab-child {
position: absolute;
left: -99999em;
top: -99999em;
opacity: 1;
z-index: 1;
}
input.tgl-radio-tab-child+label {
cursor: pointer;
float: left;
border: 1px solid #aaa;
margin-right: -1px;
padding: .5em 1em;
position: relative;
}
input.tgl-radio-tab-child+label:hover {
background-color: #eee;
}
[type=radio]:checked+label {
background-color: #c30;
z-index: 1;
}
<label for="abc">ABC<span style="color: red;">*</span></label>
<div class="form-check">
<div class="tgl-radio-tabs">
<input id="x" type="radio" class="form-check-input tgl-radio-tab-child" name="abcorigin"><label for="x" class="radio-inline">ABCDEFGHIJKL</label>
<input id="y" type="radio" class="form-check-input tgl-radio-tab-child" name="abcorigin"><label for="y" class="radio-inline">MNOPQRSTUVWXYZ</label>
</div>
</div>
I've been trying to customize the default radio button to look something like on/off button.
I've already created one using 2 images (using javascript) for an on and off state, but there's no animation for transition between the two states.
Is there a way to achieve this using pure css(+ animation)?
I need buttons like these-
Here you go you can also do this with checkbox
#mc, #mc2, #mc3 {
display: none;
}
.switch {
background: gray;
width: 40px;
height: 20px;
border-radius: 10px;
display: block;
position: relative;
margin: 10px;
}
.switch:hover {
cursor: pointer
}
.switch:after {
content: "";
height: 18px;
width: 18px;
border-radius: 9px;
display: block;
position: absolute;
top: 1px;
left: 1px;
background: lightblue;
transition: ease-out 0.5s;
}
input[type=radio]:checked + label:after,
input[type=checkbox]:checked + label:after{
left: calc(100% - 19px);
background: lightgreen;
}
<p>Radio</p>
<input type="radio" id="mc" name="Switch" />
<label class="switch" for="mc"></label>
<input type="radio" id="mc2" name="Switch" />
<label class="switch" for="mc2"></label>
<p>Checkbox</p>
<input type="checkbox" id="mc3" name="Switch" />
<label class="switch" for="mc3"></label>
To get transition between the two state (on/off), style the :checked pseudo class.
The :checked pseudo class matches every checked <input> element (radio, checkbox and option).
/* The container */
.switch {
position: relative;
display: inline-block;
vertical-align: middle;
margin-right: .5em;
width: 46px;
height: 24px;
}
/* Hide the browser's default radio */
.switch input[type=radio] {
position: absolute;
opacity: 0;
}
/* Create a custom switch */
.switch .slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 34px;
border: 1px solid #daa2e6;
transition: .2s;
}
/* Create the indicator/dot */
.switch .slider::before {
position: absolute;
top: 2px;
left: 4px;
content: "";
height: 18px;
width: 18px;
border-radius: 50%;
background-color: #bababa;
transition: .2s;
}
/* When the switch is checked, add a blue background */
.switch input[type=radio]:checked + .slider {
background-color: #007bff;
}
/* When the switch is checked, change position of the indicator/dot */
.switch input[type=radio]:checked + .slider::before {
background-color: #fff;
-webkit-transform: translateX(18px);
-ms-transform: translateX(18px);
transform: translateX(18px);
}
/* When the switch gets focus, add a shadow */
.switch input[type=radio]:focus + .slider {
box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
border-color: #80bdff;
}
<p>
<label class="switch">
<input type="radio" name="country">
<span class="slider"></span>
</label> United States
</p>
<p>
<label class="switch">
<input type="radio" name="country">
<span class="slider"></span>
</label> Canada
</p>
<p>
<label class="switch">
<input type="radio" name="country" checked>
<span class="slider"></span>
</label> United Kingdom
</p>
<p>
<label class="switch">
<input type="radio" name="country">
<span class="slider"></span>
</label> India
</p>
I was looking for a good Material Design input tutorial - which I found here -, but when I tried to apply this in my code, the underlines don't match up.
The underline when focused is shorter than the regular border-bottom.
Here's the live example of what I mean: Codepen
And here's the code:
input {
font-size: 18px;
padding: 10px 10px 10px 5px;
display: block;
width: 300px;
border: none;
border-bottom: 1px solid #757575;
}
.bar {
position: relative;
display: block;
width: 300px;
}
.bar:before,
.bar:after {
content: '';
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: rgba(37, 116, 169, 0.50);
transition: 0.2s ease all;
}
.bar:before {
left: 50%;
}
.bar:after {
right: 50%;
}
/* active state */
input:focus ~ .bar:before,
input:focus ~ .bar:after {
width: 50%;
}
<form>
<div class="group">
<input type="text" required>
<span class="bar"></span>
<label>Name</label>
</div>
<div class="group">
<input type="text" required>
<span class="bar"></span>
<label>Email</label>
</div>
</form>
Is there anyone who knows why this happens?
You need to set the box-sizing:border-box; on the input elements:
input {
font-size: 18px;
padding: 10px 10px 10px 5px;
display: block;
width: 300px;
border: none;
border-bottom: 1px solid #757575;
box-sizing:border-box;
outline:none;
}
.bar {
position: relative;
display: block;
width: 300px;
}
.bar:before,
.bar:after {
content: '';
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: rgba(37, 116, 169, 0.50);
transition: 0.2s ease all;
}
.bar:before {
left: 50%;
}
.bar:after {
right: 50%;
}
/* active state */
input:focus ~ .bar:before,
input:focus ~ .bar:after {
width: 50%;
}
<form>
<div class="group">
<input type="text" required>
<span class="bar"></span>
<label>Name</label>
</div>
<div class="group">
<input type="text" required>
<span class="bar"></span>
<label>Email</label>
</div>
</form>
That, or set the width of the spans to about 315px which should match the width of the inputs when you factor in the border and padding.