Having trobule getting two DIVs to vertically align - html

I have two DIVs
<div class=“address”>
<div class="field"><input placeholder="City" class="textField" type="text" name="user[address][city]" id="user_address_city"></div>
<div class="select"><select class="selectField selectMenu form-control select-hidden" name="user[address][state]" id="user_address_state"><option value="">Select State</option>
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option></select><div class="select-styled">Select State</div><ul class="select-options"><li rel="">Select State</li><li rel="AL">Alabama</li><li rel="WY">Wyoming</li></ul></div>
</div>
The problem I’m having is aligning both DIVs on the same vertical plain. Per this Fiddle — https://jsfiddle.net/7e0jthv1/ , the select menu is aligning at a higher vertical position than the other text field. This is the style I have for my input element
input {
font-size: 16px;
line-height: 18px;
box-sizing: border-box;
font-family: inherit;
padding: 0.4rem 0;
text-indent: 0.8rem;
border: none;
outline: none;
margin: 0;
background-color: transparent;
}
and this is the style for the DIV containing the select menu …
.select {
cursor: pointer;
display: inline-block;
position: relative;
font-size: 16px;
color: #fff;
width: 220px;
height: 40px;
}
I can’t figure out why things aren’t aligning at the top.

You need to add vertical-align to your .select and .field containers.
You can do something like this and it will make the elements line up correctly:
.select, .field {vertical-align:top;}
https://jsfiddle.net/p40jeq9L/
EDIT: This is due to the fact that the elements are inline-block. The accepted answer in this post explains the reasons why pretty well: My inline-block elements are not lining up properly

Just add property CSS width.
So add width:100% to divs class="select" and class="field".
jsfiddle

You can do it using display: table, table-cell :
HTML :
<div class="profileField address">
<label for="user_address_address">Hometown</label><br>
<div class="fields-container">
<div class="field"><input placeholder="City" class="textField" type="text" name="user[address][city]" id="user_address_city"></div>
<div class="select">
<select class="selectField selectMenu form-control select-hidden" name="user[address][state]" id="user_address_state">
<option value="">Select State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
...
</select>
<div class="select-styled">Select State</div><ul class="select-options"><li rel="">Select State</li><li rel="AL">Alabama</li><li rel="AK">Alaska</li><li rel="AZ">Arizona</li><li rel="AR">Arkansas</li><li rel="CA">California</li><li rel="CO">Colorado</li><li rel="CT">Connecticut</li><li rel="DE">Delaware</li><li rel="DC">District of Columbia</li><li rel="FL">Florida</li><li rel="GA">Georgia</li><li rel="HI">Hawaii</li><li rel="ID">Idaho</li><li rel="IL">Illinois</li><li rel="IN">Indiana</li><li rel="IA">Iowa</li><li rel="KS">Kansas</li><li rel="KY">Kentucky</li><li rel="LA">Louisiana</li><li rel="ME">Maine</li><li rel="MD">Maryland</li><li rel="MA">Massachusetts</li><li rel="MI">Michigan</li><li rel="MN">Minnesota</li><li rel="MS">Mississippi</li><li rel="MO">Missouri</li><li rel="MT">Montana</li><li rel="NE">Nebraska</li><li rel="NV">Nevada</li><li rel="NH">New Hampshire</li><li rel="NJ">New Jersey</li><li rel="NM">New Mexico</li><li rel="NY">New York</li><li rel="NC">North Carolina</li><li rel="ND">North Dakota</li><li rel="OH">Ohio</li><li rel="OK">Oklahoma</li><li rel="OR">Oregon</li><li rel="PA">Pennsylvania</li><li rel="PR">Puerto Rico</li><li rel="RI">Rhode Island</li><li rel="SC">South Carolina</li><li rel="SD">South Dakota</li><li rel="TN">Tennessee</li><li rel="TX">Texas</li><li rel="UT">Utah</li><li rel="VT">Vermont</li><li rel="VA">Virginia</li><li rel="WA">Washington</li><li rel="WV">West Virginia</li><li rel="WI">Wisconsin</li><li rel="WY">Wyoming</li></ul></div>
</div>
</div>
CSS :
#import url("http://fonts.googleapis.com/css?family=Lato");
.profileField {
padding: 10px;
font-family: 'Oxygen', sans-serif;
font-weight: 300;
font-size: 20px;
}
.profileField label {
margin-bottom: 10px;
float: left;
width: 100%;
}
.field {
border: 1px solid rgba(74, 74, 76, 0.5) !important;
float: none;
display: table-cell;
margin: 15px;
}
input {
font-size: 16px;
line-height: 18px;
box-sizing: border-box;
font-family: inherit;
padding: 0.4rem 0;
text-indent: 0.8rem;
border: none;
outline: none;
margin: 0;
background-color: transparent;
}
.address {
display: inline-block;
}
.select-hidden {
display: none;
visibility: hidden;
padding-right: 10px;
}
.select {
cursor: pointer;
display: inline-block;
position: relative;
font-size: 16px;
color: #fff;
width: 220px;
height: 40px;
display: table-cell;
}
.select-styled {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 15px;
background-color: #c0392b;
padding: 8px 15px;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.select-styled:after {
content: "";
width: 0;
height: 0;
border: 7px solid transparent;
border-color: #fff transparent transparent transparent;
position: absolute;
top: 16px;
right: 10px;
}
.select-styled:hover {
background-color: #b83729;
}
.select-styled:active, .select-styled.active {
background-color: #ab3326;
}
.select-styled:active:after, .select-styled.active:after {
top: 0px;
border-color: transparent transparent #fff transparent;
}
.select-options {
display: none;
position: absolute;
top: 100%;
right: 0;
left: 0;
z-index: 999;
margin: 0;
padding: 0;
list-style: none;
background-color: #ab3326;
}
.select-options li {
margin: 0;
padding: 12px 0;
text-indent: 15px;
border-top: 1px solid #962d22;
-webkit-transition: all 0.15s ease-in;
transition: all 0.15s ease-in;
}
.select-options li:hover {
color: #c0392b;
background: #fff;
}
.select-options li[rel="hide"] {
display: none;
}
.fields-container {
display: table;
}
FIDDLE

Related

How to add <select> floating label without using required

I went through most of the questions related to this. But I couldn't find out the solution. I have provided the code so far. My requirement is to remove the required from the <select> and work this as it is. If I remove it at the moment, this will not work as expected.
I know this is really possible via JavaScript/jQuery but I want to do this with CSS.
label.input {
position: relative;
overflow: hidden;
}
span.input__label {
position: absolute;
left: 0;
padding: 7px 12px;
width: 240px;
font-size: 14px;
color: #828282;
pointer-events: none;
height: 35px;
}
.input:active::after {
transform: rotate(-180deg);
}
.input__field:invalid {
color: transparent;
transition: 200ms color linear 100ms;
}
.input__field:valid + .input__label, .input__field:focus:valid + .input__label {
transform: translate(0.5em, -10%);
transition: 200ms transform ease-out;
color: #000;
top: 5px;
left: 2px;
padding: 0 7px;
font-size: 10px;
}
.input__label {
position: absolute;
left: 0;
top: 0;
right: 0;
padding: 1.5rem 1.5rem 0;
pointer-events: none;
transform-origin: 0 0;
transition: 200ms transform ease-out 200ms;
will-change: transform;
}
select.form-select {
width: 240px;
font-size: 14px;
color: #828282;
display: inline-block;
}
select.form-select option {
color: #828282;
}
.form-select:focus {
border-color: #dcd9d6;
outline: 0;
box-shadow: none;
}
form select {
width: 240px;
height: 52px;
padding: 16px 11px;
font-weight: normal;
font-size: 14px;
color: #828282;
border-radius: 5px;
background: #fff;
border: 1px solid #dcd9d6;
margin-right: 7px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<label class="input">
<select name="max-price" class="input__field form-select" id="maxPrice" required>
<option value="" selected disabled hidden></option>
<option value="100,000">100,000</option>
<option value="200,000">200,000</option>
<option value="300,000">300,000</option>
</select>
<span class="input__label">Max Price</span>
</label>
Hope it's work for you !!!
You need to add onchange event in select.
onchange=" this.dataset.select = this.value;
label.input {
position: relative;
overflow: hidden;
}
span.input__label {
position: absolute;
left: 0;
padding: 7px 12px;
width: 240px;
font-size: 14px;
color: #828282;
pointer-events: none;
height: 35px;
}
.input:active::after {
transform: rotate(-180deg);
}
.input__field:invalid {
color: transparent;
transition: 200ms color linear 100ms;
}
.input__label {
position: absolute;
left: 0;
top: 0;
right: 0;
padding: 1.5rem 1.5rem 0;
pointer-events: none;
transform-origin: 0 0;
transition: 200ms transform ease-out 200ms;
will-change: transform;
opacity: 0;
}
select.form-select {
width: 240px;
font-size: 14px;
color: #828282;
display: inline-block;
}
select.form-select option {
color: #828282;
}
.form-select:focus {
border-color: #dcd9d6;
outline: 0;
box-shadow: none;
}
form select {
width: 240px;
height: 52px;
padding: 16px 11px;
font-weight: normal;
font-size: 14px;
color: #828282;
border-radius: 5px;
background: #fff;
border: 1px solid #dcd9d6;
margin-right: 7px;
}
select[data-select]+ .input__label {
transform: translate(0.5em, -10%);
transition: 200ms transform ease-out;
color: #000;
top: 5px;
left: 2px;
padding: 0 7px;
font-size: 10px;
opacity: 1;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<label class="input">
<select onchange=" this.dataset.select = this.value; " name="max-price" class="input__field form-select" id="maxPrice">
<option value="" selected disabled hidden>Max Price</option>
<option value="100,000">100,000</option>
<option value="200,000">200,000</option>
<option value="300,000">300,000</option>
</select>
<span class="input__label">Max Price</span>
</label>

Height of the select option box

I have a form in which one input field is select and it has few option.I am not able to increase the height of the option box and background color.presently it has white colour as given in the picture My html code and css code is below
.select2 {
width: 100%;
overflow: hidden;
font-size: 20px;
padding: 4px 0;
margin: 4px 0;
border-bottom: 2px solid black;
background-color: transparent;
}
.select2 option{
width: 26px;
background-color: none ;
border: none;
background: none;
color: blue;
font-size: 20px;
font-weight:bold;
float: left;
margin: 0 10px;
white-sapce: no-wrap;
text-overflow: ellipsis;
}
.select2 after {
!content: 'Select Role';
font-family: 'material icons';
font-size: 24px;
color: red;
position: absolute;
right: 10px;
top: 10%;
transform: translateY(-50%);
pointer-events: none;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
<div class="select2">
<i class="fas fa-user-lock" style="color:black; padding:10px;"> Role</i>
<select >
<option value=""></option>
<option value="user">USER</option>
<option value="rec">Recommending Officer</option>
<option value="store">Store</option>
</select>
</div>
You can use this to increase height:
.select2 select{
height: 50px;
background: transparent;
}
Add more properties here to style the box.
Also correct way to use before and after is :
.select2::after {
....
}
Codepen
Try giving style to select tag, this might works!
select{
width: 50%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 20px;
}
Try this
.select2 {
width: 100%;
overflow: hidden;
font-size: 20px;
padding: 4px 0;
margin: 4px 0;
}
select{
height:30px;
border-bottom: 2px solid black;
background-color: transparent;
}

Customized select drop down arrow not working

I have tried to customized the select drop down. But the arrow of the select is not working. I want to make it as this image. But it is how far I could reach. Here is the image of how I want it to be. Please have a look at it.
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="selectdiv ">
<label>
<select>
<option selected> Select Box </option>
<option>Option 1</option>
<option>Option 2</option>
<option>Last long option</option>
</select>
</label>
</div>
CSS
body {
background: #f2f2f2;
}
.selectdiv {
position: relative;
/*Don't really need this just for demo styling*/
float: left;
min-width: 150px;
margin: 50px 33%;
background:rgba(43, 43, 43, 0.4);
border-radius: 5px 0 0 5px;
padding: 5px;
}
.selectdiv:after {
content: '\f078';
font: normal normal normal 17px/1 FontAwesome;
color: #2B2B2B;
right: -44px;
top: 0px;
height: 33px;
padding: 15px 12px 0px 12px;
border:1px solid #2B2B2B;
border-radius: 0 5px 5px 0;
position: absolute;
}
/* IE11 hide native button (thanks Matt!) */
select::-ms-expand {
display: none;
}
.selectdiv select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* Add some styling */
display: block;
width: 100%;
max-width: 150px;
margin: 5px 0px 5px 0px;
padding: 0px 24px;
font-size: 16px;
line-height: 1.75;
color: #333;
background: transparent;
-ms-word-break: normal;
word-break: normal;
border: 0;
border-bottom: 1px solid #fff;
outline:none;
}
I have added the codepen.io link here. Please look at it. https://codepen.io/anon/pen/vzKrXK
modify your .selectdiv:after css like this, change url with any image you want:
.selectdiv:after {
content: '';
background-color: #fff;
background: url(http://icocentre.com/Icons/g-arrow-down.png?size=16) no- repeat right #ddd;
-webkit-appearance: none;
background-position-x: 5px;
width: 10px;
font: normal normal normal 17px/1 FontAwesome;
color: #0ebeff;
right: 11px;
top: 6px;
height: 34px;
padding: 15px 0px 0px 8px;
border-left: 1px solid #0ebeff;
position: absolute;
pointer-events: none;
}

How to design an Html input with floating label using only CSS and HTML?

How to design an input text like in material design with a label that floats up and it doesn't overlap the content when the input is not focused, how can i implement that without using Materialise.CSS or any other library
I prefer this technique for its markup simplicity, accessibility, and keyboard-friendliness.
It uses relative and absolute positioning (an absolute label inside a relative container) and never "replaces" the label with another element (such as with the placeholder pseudo-element) because replacement techniques cause flickering in my experience. It also manages the pointer events so that the label never gets in the way of clicking to select the input (but once it's out of the way, its text is selectable).
I've used ems, since we're dealing with animated text. This should allow the technique to scale to different font sizes without modifying the offsets used for padding and margins.
This uses the required attribute and the :valid selector to check whether an input was left blank (in which case, the label drops back down). If this doesn't work for your use case, it can be worked around by adding and removing an empty class to the input using JavaScript (that's what the last CSS ruleset is for). Another option would be to use :placeholder-shown with a dummy placeholder, if you're okay with not supporting Microsoft Edge. Remember, CSS's :empty selector doesn't work the way you'd think it might on HTML inputs.
#import url('https://fonts.googleapis.com/css?family=Roboto');
body
{
/* just to make it feel a little more at home */
font-family: 'Roboto', sans-serif;
}
.floating-label
{
position: relative;
margin-top: 1.75em;
}
.floating-label input[type="text"]
{
border: none;
border-bottom: 1px solid gray;
margin-bottom: 1px;
}
.floating-label input[type="text"]:hover
{
border-bottom: 2px solid black;
margin-bottom: 0;
}
.floating-label input[type="text"]:focus,
.floating-label input[type="text"]:active
{
outline: none;
border-bottom: 2px solid #2196f3;
margin-bottom: 0;
}
.floating-label input[type="text"] + label
{
position: absolute;
pointer-events: none;
bottom: 0.1em;
left: 0.1em;
color: gray;
font-size: 1.0em;
transition: margin 0.2s ease,
color 0.2s ease,
font-size 0.2s ease;
}
.floating-label input[type="text"]:focus + label,
.floating-label input[type="text"]:active + label,
.floating-label input[type="text"]:valid + label
{
pointer-events: auto;
margin-bottom: 1.75em;
font-size: 0.7em;
}
.floating-label input[type="text"]:focus + label,
.floating-label input[type="text"]:active + label
{
color: #2196f3;
}
.floating-label input[type="text"].empty:not(:focus) + label,
.floating-label input[type="text"].empty:not(:active) + label
{
pointer-events: none;
margin-bottom: 0;
color: gray;
font-size: 1.0em;
}
<div class="floating-label">
<input id="first" type="text" required>
<label for="first">First Name</label>
</div>
<div class="floating-label">
<input id="last" type="text" required>
<label for="last">Last Name</label>
</div>
This is how I've done it previously.
The CSS has be processed from SCSS which is why it's so specific.
.container {
width: 15%;
}
.container .form-group {
margin: 0 0 16px;
}
.container .form-group.field--invalid > .field__input-container .field__decoration:before {
border-color: #e4134f;
width: 100%;
}
.container .form-group .field__input-container {
position: relative;
margin-bottom: 8px;
padding-top: 16px;
}
.container .form-group .field__input-container .field__input {
font-size: 18px;
line-height: 28px;
font-weight: 700;
letter-spacing: -1px;
background: transparent;
border: 0;
outline: 0;
padding-top: 20px;
padding-bottom: 2px;
width: 100%;
}
.container .form-group .field__input-container .field__input:focus + .field__label, .container .form-group .field__input-container .field__input:valid + .field__label {
font-size: 14px;
line-height: 20px;
bottom: 50%;
}
.container .form-group .field__input-container .field__input:focus ~ .field__decoration:before, .container .form-group .field__input-container .field__input:valid ~ .field__decoration:before {
width: 100%;
}
.container .form-group .field__input-container .field__input:focus ~ .arrow-down {
border-color: transparent;
}
.container .form-group .field__input-container .field__input--dropdown {
border-color: #000;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.container .form-group .field__input-container .field__input--dropdown + .field__label {
color: #000;
}
.container .form-group .field__input-container select::-ms-expand {
display: none;
}
.container .form-group .field__input-container .field__label {
color: #848484;
font-size: 19px;
line-height: 28px;
bottom: 2px;
left: 0;
pointer-events: none;
position: absolute;
top: auto;
transition: bottom 0.3s ease, font-size 0.3s ease, line-height 0.3s ease;
margin: 0;
padding: 0;
border: 0;
vertical-align: baseline;
}
.container .form-group .field__input-container .field__label span {
margin: 0;
padding: 0;
border: 0;
vertical-align: baseline;
}
.container .form-group .field__input-container .field__decoration {
border-bottom: 1px solid;
border-color: #000;
}
.container .form-group .field__input-container .field__decoration:before {
display: block;
position: absolute;
content: "";
left: 0;
bottom: 0;
width: 0;
border-bottom: 2px solid;
border-color: #000;
transition: width 0.3s ease, border-color 0.3s ease;
}
.container .form-group .field__input-container .arrow-down {
position: absolute;
right: 0;
bottom: 12px;
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 6px solid #000;
transition: border-color 0.3s ease;
z-index: -1;
}
<div class="container">
<div id="user-first-name" class="form-group"><!-- field--invalid -->
<div class="field__input-container">
<input type="text" class="field__input" id="input-first-name" name="input-first-name" required value="" autocomplete="off">
<label class="field__label" id="username-label" for="input-first-name"><span>First name</span></label>
<div class="field__decoration"></div>
</div>
</div>
<div id="user-last-name" class="form-group"><!-- field--invalid -->
<div class="field__input-container">
<input type="text" class="field__input" id="input-last-name" name="input-last-name" required value="" autocomplete="off">
<label class="field__label" id="username-label" for="input-last-name"><span>Last name</span></label>
<div class="field__decoration"></div>
</div>
</div>
<div id="user-title" class="form-group"><!-- field--invalid -->
<div class="field__input-container">
<select class="field__input field__input--dropdown" id="input-title" name="input-title" required autocomplete="off">
<option selected value="" disabled hidden></option>
<option value="" disabled>Please select</option>
<option value="mr">Mr</option>
<option value="mrs">Mrs</option>
<option value="ms">Ms</option>
<option value="dr">Dr</option>
<option value="other">Other</option>
<option value="prefer not to say">Prefer not to say</option>
</select>
<label class="field__label" id="username-label" for="input-title"><span>Title</span></label>
<div class="field__decoration"></div>
<div class="arrow-down"></div>
</div>
</div>
</div>

Add animation to border bottom on input

I want the color of the border-bottom of my input to change with an animation when clicked. Similar to the yellow line one this. I want this to be on all the input boxes and the select.
.input_container{
display: inline-block;
text-align: center;
}
.awsome_input{
padding: 5px 10px;
border: none;
background: transparent;
display: block;
}
.awsome_input_border{
display:inline-block;
width:0px;
height: 2px;
background: #FEC938;
position: relative;
top:-5px;
-webkit-transition: all ease-in-out .15s;
-o-transition: all ease-in-out .15s;
transition: all ease-in-out .15s;
}
.awsome_input:hover,
.awsome_input:active,
.awsome_input:focus{
outline: none;
}
.awsome_input:hover+.awsome_input_border,
.awsome_input:active+.awsome_input_border,
.awsome_input:focus+.awsome_input_border{
width:100%;
}
<div class="input_container">
<input type="text" class="awsome_input"
placeholder="What do you think?"/>
<span class="awsome_input_border"/>
</div>
I've tried to recreate this in my code but I cant seem to get it right. Any idea how to do this?
I understand that the span is what creates the yellow line on the snippet but can I recreate this instead to change the border-color instead of adding another line.
My code.
<!DOCTYPE html>
<html>
<head>
<title>form</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="signup-form">
<form>
<input type="text" name="firstname" class="line-animation">
<span class="awsome_input_border" />
<input type="text" name="lastname" class="line-animation">
<span class="awsome_input_border" />
<select name="country">
<option value="sweden">Sweden</option>
<option value="uk">United Kingdom</option>
<option value="us">United States</option>
<option value="canada">Canada</option>
</select>
<span class="awsome_input_border" />
</form>
</div>
</body>
</html>
.signup-form {
background-color: #efefef;
width: 50%;
}
.signup-form form {
padding: 20px 10px
}
.signup-form input[type=text], select {
border: none;
border-bottom: 2px solid darkgrey;
background-color: inherit;
margin-right: 20px;
}
.signup-form input[type=text]:focus, select:focus {
outline: none;
border-bottom: 2px solid #02add7;
}
Well the clue was in the code you provided at the beginning, you need to set what happens to the sibling element on focus:
HTML
<!DOCTYPE html>
<html>
<head>
<title>form</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="signup-form">
<form>
<div class="form-group">
<input type="text" name="firstname" class="line-animation" placeholder="firstname">
<div class="line"></div>
</div>
<div class="form-group">
<input type="text" name="lastname" class="line-animation" placeholder="lastname"><div class="line"></div>
</div>
<div class="form-group">
<select name="country">
<option value="sweden">Sweden</option>
<option value="uk">United Kingdom</option>
<option value="us">United States</option>
<option value="canada">Canada</option>
</select><div class="line"></div>
</div>
</form>
</div>
</body>
</html>
CSS
.signup-form {
background-color: #efefef;
width: 50%;
}
.signup-form form {
padding: 20px 10px
}
.signup-form input[type=text], select {
border: none;
border-bottom: 2px solid darkgrey;
background-color: inherit;
display: block;
width: 100%;
margin: none;
}
.signup-form input[type=text]:focus, select:focus {
outline: none;
}
.form-group {
text-align: center;
}
.form-group .line {
height: 2px;
width: 0px;
position: absolute;
background-color: darkgrey;
display: inline-block;
transition: .3s width ease-in-out;
position: relative;
top: -14px;
}
.signup-form input[type=text]:focus+.line, select:focus+.line {
width: 100%;
background-color: #02add7;
}
Fiddle: https://jsfiddle.net/6xjyw21m/
Try this simple example. I am not using any span and only using border css
input {
border: none;
padding-bottom: 5px;
transition: 0.2s ease all;
}
input:focus{
outline: none;
border-bottom: 2px solid yellow;
}
input:hover {
border-bottom: 2px solid yellow;
}
select {
border: none;
background-color: white;
}
select:hover {
border-bottom: 2px solid yellow;
}
select:focus{
outline: none;
}
<h3>INPUT</h3>
<input type="text" placeholder="What do you think?" />
<h3>SELECT</h3>
<select name="country">
<option value="sweden">Sweden</option>
<option value="uk">United Kingdom</option>
<option value="us">United States</option>
<option value="canada">Canada</option>
</select>
Please check the below sample
body {
background: #ccc;
}
.custom-form {
font-family: 'Roboto', sans-serif;
font-weight: 400;
font-size: 16px;
max-width: 360px;
margin: 40px auto 40px;
background: #fff;
padding: 40px;
border-radius: 4px;
}
.custom-form .btn-primary {
background-color: #8e44ad;
border-color: #8e44ad;
}
.custom-form .form-group {
position: relative;
padding-top: 16px;
margin-bottom: 16px;
}
.custom-form .form-group .animated-label {
position: absolute;
top: 20px;
left: 0;
bottom: 0;
z-index: 2;
width: 100%;
font-weight: 300;
opacity: 0.5;
cursor: text;
transition: 0.2s ease all;
margin: 0;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.custom-form .form-group .animated-label:after {
content: '';
position: absolute;
bottom: 0;
left: 45%;
height: 2px;
width: 10px;
visibility: hidden;
background-color: #8e44ad;
transition: 0.2s ease all;
}
.custom-form .form-group.not-empty .animated-label {
top: 0;
font-size: 12px;
}
.custom-form .form-group .form-control {
position: relative;
z-index: 1;
border-radius: 0;
border-width: 0 0 1px;
border-bottom-color: rgba(0, 0, 0, 0.25);
height: auto;
padding: 3px 0 5px;
}
.custom-form .form-group .form-control:focus {
box-shadow: none;
border-bottom-color: rgba(0, 0, 0, 0.12);
}
.custom-form .form-group .form-control:focus ~ .animated-label {
top: 0;
opacity: 1;
color: #8e44ad;
font-size: 12px;
}
.custom-form .form-group .form-control:focus ~ .animated-label:after {
visibility: visible;
width: 100%;
left: 0;
}
<div>
<div>
<form action="#" class="custom-form">
<h3 class="text-center">Animated Form</h3>
<div class="form-group" ng-class="{'not-empty': userName.length}">
<input type="text" class="form-control" name="user" id="user" ng-model="userName"/>
<label for="user" class="animated-label">Username</label>
</div>
<div class="form-group" ng-class="{'not-empty': passWord.length}">
<input type="password" class="form-control" name="pass" id="pass" ng-model="passWord"/>
<label for="pass" class="animated-label">Password</label>
</div>
<div class="submit">
<button class="btn btn-primary btn-block" disabled>Send</button>
</div>
</form>
</div>
</div>