I couldn't find any relevant information and not even sure it's feasible in HTML, but I would like to display a Label line above the value in a select field, like the "EXP MONTH/YEAR" in the following image:
Is that doable? I've been searching for a way to implement it for a few days days to no avail. Thanks!
I may be a little bit late, but: You do not need anything special, it's simply formating.
Put label on top of form, wrap both label and select in a div, then adjust background colors and borders. See the example:
.select-wrap
{
border: 1px solid #777;
border-radius: 4px;
margin-bottom: 10px;
padding: 0 5px 5px;
width:200px;
background-color:#ebebeb;
}
.select-wrap label
{
font-size:10px;
text-transform: uppercase;
color: #777;
padding: 2px 8px 0;
}
select
{
background-color: #ebebeb;
border:0px;
}
<div class="select-wrap">
<label>Color</label>
<select name="color" style="width: 100%;">
<option value="">---</option>
<option value="yellow">Yellow</option>
<option value="red">Red</option>
<option value="green">Green</option>
</select>
</div>
UPDATE
I somehow remembered that I have this post. As I have improved it for personal usage, and this is version is better (you can click anywhere inside select - it will trigger dropdown, while on previous version you couln't) I thought I should share an update I have made to my code and used since.
.select-wrap {
border: 1px solid #777;
border-radius: 4px;
padding: 0 5px;
width:200px;
background-color:#fff;
position:relative;
}
.select-wrap label{
font-size:8px;
text-transform: uppercase;
color: #777;
padding: 0 8px;
position: absolute;
top:6px;
}
select{
background-color: #fff;
border:0px;
height:50px;
font-size: 16px;
}
<div class="select-wrap">
<label>Color</label>
<select name="color" style="width: 100%;">
<option value="">---</option>
<option value="yellow">Yellow</option>
<option value="red">Red</option>
<option value="green">Green</option>
</select>
</div>
Try with the below code, I have refer it from here, https://codepen.io/chriscoyier/pen/CiflJ
It's not the exact what you want I think, but it is similar to that and more jazzy, so just play with this, might be you like it.
form {
width: 320px;
float: left;
margin: 20px;
}
form > div {
position: relative;
overflow: hidden;
}
form input, form textarea, form select {
width: 100%;
border: 2px solid gray;
background: none;
position: relative;
top: 0;
left: 0;
z-index: 1;
padding: 8px 12px;
outline: 0;
}
form input:valid, form textarea:valid, form select:valid {
background: white; }
form input:focus, form textarea:focus, form select:focus {
border-color: grey; }
form input:focus + label, form textarea:focus + label, form select:focus + label {
background: grey;
color: white;
font-size: 70%;
padding: 1px 6px;
z-index: 2;
text-transform: uppercase; }
form label {
transition: background 0.2s, color 0.2s, top 0.2s, bottom 0.2s, right 0.2s, left 0.2s;
position: absolute;
color: #999;
padding: 7px 6px; }
form textarea {
display: block;
resize: vertical; }
form.go-bottom input, form.go-bottom textarea, form.go-bottom select {
padding: 12px 12px 12px 12px; }
form.go-bottom label {
top: 0;
bottom: 0;
left: 0;
width: 100%; }
form.go-bottom input:focus, form.go-bottom textarea:focus, form.go-bottom select:focus {
padding: 4px 6px 20px 6px; }
form.go-bottom input:focus + label, form.go-bottom textarea:focus + label, form.go-bottom select:focus + label {
top: 100%;
margin-top: -16px; }
<form class="go-bottom">
<h2>To Bottom</h2>
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<br/>
<div>
<select id="car">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<label for="car">Car</label>
</div>
<br/>
<div>
<textarea id="message" name="phone" required></textarea>
<label for="message">Message</label>
</div>
</form>
Related
I had this piece of CSS implemented to have a transparent autofill background. But something has recently changed that it stopped working?
#-webkit-keyframes autofill {
to {
color: white;
background: transparent;
}
}
input:-webkit-autofill {
-webkit-animation-name: autofill;
-webkit-animation-fill-mode: both;
}
Is there a fix to this?
form {
background-color: red;
}
div {
margin: 15px 0;
position: relative;
width: 360px;
color: red;
background-color: red;
}
textarea,
select,
input {
height: 30px;
line-height: 30px;
border-radius: 5px;
border: 1px solid #000;
width: 100%;
box-sizing: border-box;
padding: 0 10px;
color: red;
background-color: red;
}
textarea {
height: 200px;
color: red;
background-color: red;
}
textarea+label {
width: calc(100% - 2px) !important;
top: 1px;
box-sizing: border-box;
border-radius: 5px 5px 0 0;
text-align: center;
color: red;
}
textarea:invalid,
select:invalid,
input:invalid {
box-shadow: none;
color: red;
}
textarea:invalid+label,
select:invalid+label,
input:invalid+label {
padding: 0 10px;
max-width: 360px;
color: red;
}
textarea:focus+label,
select:focus+label,
input:focus+label,
label {
position: absolute;
background: #a4a290;
max-width: 0;
padding: 0;
overflow: hidden;
left: 1px;
top: 1px;
height: 28px;
font: 14px/28px sans-serif;
-webkit-transition: all 0.25s;
-o-transition: all 0.25s;
transition: all 0.25s;
color: red;
border-radius: 5px 0 0 5px;
}
textarea:focus+label {
height: 0;
color: red;
#-webkit-keyframes autofill {
to {
color: white;
background: transparent;
}
}
input:-webkit-autofill {
-webkit-animation-name: autofill;
-webkit-animation-fill-mode: both;
}
<form>
<div>
<input type="text" id="firstname" required/>
<label for="firstname">First Name</label>
</div>
<div>
<input type="text" id="secondname" required/>
<label for="secondname">Second Name</label>
</div>
<div>
<select id="type" required>
<option value=""></option>
<option value="1">Type 1</option>
<option value="2">Type 2</option>
<option value="3">Type 3</option>
<option value="4">Type 4</option>
</select>
<label for="type">Select type...</label>
</div>
<div>
<textarea id="comment" required/></textarea>
<label for="comment">Comment</label>
</div>
</form>
Just this would do the job perfectly :
input:-webkit-autofill {
-webkit-text-fill-color: transparent;
transition: background-color 5000s ease-in-out 0s;
}
form {
background-color: red;
}
div {
margin: 15px 0;
position: relative;
width: 360px;
color: red;
background-color: red;
}
textarea,
select,
input {
height: 30px;
line-height: 30px;
border-radius: 5px;
border: 1px solid #000;
width: 100%;
box-sizing: border-box;
padding: 0 10px;
color: red;
background-color: red;
}
textarea {
height: 200px;
color: red;
background-color: red;
}
textarea+label {
width: calc(100% - 2px) !important;
top: 1px;
box-sizing: border-box;
border-radius: 5px 5px 0 0;
text-align: center;
color: red;
}
textarea:invalid,
select:invalid,
input:invalid {
box-shadow: none;
color: red;
}
textarea:invalid+label,
select:invalid+label,
input:invalid+label {
padding: 0 10px;
max-width: 360px;
color: red;
}
textarea:focus+label,
select:focus+label,
input:focus+label,
label {
position: absolute;
background: #a4a290;
max-width: 0;
padding: 0;
overflow: hidden;
left: 1px;
top: 1px;
height: 28px;
font: 14px/28px sans-serif;
-webkit-transition: all 0.25s;
-o-transition: all 0.25s;
transition: all 0.25s;
color: red;
border-radius: 5px 0 0 5px;
}
textarea:focus+label {
height: 0;
color: red;
}
input:-webkit-autofill {
-webkit-text-fill-color: black;
transition: background-color 5000s ease-in-out 0s;
}
<form>
<div>
<input type="text" id="firstname" required />
<label for="firstname">First Name</label>
</div>
<div>
<input type="email" id="email" required />
<label for="email">Email</label>
</div>
<div>
<input type="text" id="secondname" required />
<label for="secondname">Second Name</label>
</div>
<div>
<select id="type" required>
<option value=""></option>
<option value="1">Type 1</option>
<option value="2">Type 2</option>
<option value="3">Type 3</option>
<option value="4">Type 4</option>
</select>
<label for="type">Select type...</label>
</div>
<div>
<textarea id="comment" required /></textarea>
<label for="comment">Comment</label>
</div>
</form>
Source
https://jsbin.com/zofuqunavo/
#keyframes autofill {
to {
color: white;
background: green;
}
}
input:focus {
animation-name: autofill;
animation-fill-mode: both;
}
Using input:focus selector instead of input:autofill seem fix your issue.
Autofill is a bit unstable feature, the behaviour is changed multiple times and each browser has own implementation.
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>
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>
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
I'm trying to make a search -box with categories, like Amazon. The problem is that, when I click inside the text area, the borders change color creating a bad view effect. How can I stop it?
Here is the code:
$border-color: orange;
#form-wrapper {
width: 50%;
height: 40px;
}
.nav-list {
padding: 10px 25px 10px 5px;
position: relative;
float: left;
border: 1px solid $border-color;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
#dropdown {
cursor: pointer;
position: absolute;
height: 100%;
left: 0;
top: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
border: 1px solid $border-color;
}
#dropdown:hover {
background-color: lightgray;
}
.current-selection {
display: inline-block;
font-size: 14px;
}
.in-wrap {
overflow: hidden;
height: 100%;
}
#search-box {
width: 100%;
height: 36px;
border: 1px solid $border-color;
border-left: none;
border-right: none;
line-height: 25px;
font-size: 18px;
padding-left: 100px;
}
.go-button {
float: right;
height: 100%;
background-color: orange;
border: 1px solid $border-color;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
margin: 0;
padding: 0 15px;
}
.go-button:hover {
background-color: rgb(255, 115, 0);
cursor: pointer;
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<div id="form-wrapper">
<button class="go-button fa fa-search"></button>
<span class="nav-list">
<span class="current-selection">
</span>
<select id="dropdown">
<option value="books-and-ebooks">Books & eBooks</option>
<option value="audiobooks">Audiobooks</option>
<option value="dvds">DVDs</option>
<option value="other-resources">Other Resources</option>
<option value="random">Random</option>
</select>
</span>
<div class="in-wrap">
<input type="text" name="query" id="search-box">
</div>
</div>
Now I realized that on JSFiddle is not working the same way as on codepen, so here is on codepen: http://codepen.io/1z10/pen/QEbjBx
It was happening because the browsers add outline on input field, to fix this you need to remove on input:focus the attribute outline, declaring this equals none. Like this CSS code:
#search-box:focus{
outline:none;
}
add this to your css:
#search-box:focus {
outline: none;
}
Try this it may help you. I just changed the height...
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<style>
$border-color: orange;
#form-wrapper {
width: 50%;
height: 40px;
}
.nav-list {
padding: 10px 25px 10px 5px;
position: relative;
float: left;
border: 1px solid $border-color;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
#dropdown {
cursor: pointer;
position: absolute;
height: 36px;
left: 0;
top: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
border: 1px solid $border-color;
}
#dropdown:hover {
background-color: lightgray;
}
.current-selection {
display: inline-block;
font-size: 14px;
}
textarea:focus, input:focus{
outline: none;
}
.in-wrap {
overflow: hidden;
height: 100%;
}
#search-box {
width: 100%;
height: 30px;
border: 1px solid $border-color;
border-left: none;
border-right: none;
line-height: 25px;
font-size: 18px;
padding-left: 100px;
}
.go-button {
float: right;
height: 36px;
background-color: orange;
border: 1px solid $border-color;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
margin: 0;
padding: 0 15px;
}
.go-button:hover {
background-color: rgb(255, 115, 0);
cursor: pointer;
}
</style>
<div id="form-wrapper">
<button class="go-button fa fa-search"></button>
<span class="nav-list">
<span class="current-selection">
</span>
<select id="dropdown">
<option value="books-and-ebooks">Books & eBooks</option>
<option value="audiobooks">Audiobooks</option>
<option value="dvds">DVDs</option>
<option value="other-resources">Other Resources</option>
<option value="random">Random</option>
</select>
</span>
<div class="in-wrap">
<input type="text" name="query" id="search-box">
</div>
</div>
Please, don't use outline:none; for disabling the focus outline. You are killing accessibility of the web if you do this. There is a accessible way of doing this.
Check out this article that I've written to explain how to do this correct without breaking you page for a certain segment of your users.