:root {
--secondaryGreen: rgba(114, 191, 68, 1);
--gutter: 15px;
}
.main {
margin-top: 50px;
border: 1px solid rgba(0, 0, 0, 0.13);
border-radius: 4px;
background-color: #fff;
box-shadow: 0 -1px 2px 0 rgba(0, 0, 0, .05), 0 2px 3px 0 rgba(0, 0, 0, 0.10);
display: grid;
grid-template-columns: 100%;
grid-template-rows: 60px 50px 80px 80px 80px;
}
.main > div {
padding: 0 var(--gutter);
display: flex;
flex-direction: column;
justify-content: center;
/* text-align: center; <-- horizontal centering, if needed */
border: 1px dashed red !important; /* for demonstration purposes only */
}
.main > div + div {
margin-top: 10px; /* for demonstration purposes only */
}
.title {
font-weight: 600;
color: var(--primaryBlue);
font-size: 16px;
border-bottom: 1px solid rgba(0, 0, 0, 0.13);
}
.form-group input {
background: none;
padding: 0.125rem 0.125rem 0.0625rem;
font-size: 1rem;
border-width: 0;
border-color: transparent;
transition: all 0.28s ease;
box-shadow: none;
height: 1.9rem;
}
.form-group .control-label {
order: -1;
pointer-events: none;
padding-left: var(--gutter);
font-weight: normal;
transition: all 0.28s ease;
}
.form-group .bar {
position: relative;
border-bottom: 0.0625rem solid #999;
display: block;
}
.form-group .bar::before {
content: '';
height: 0.125rem;
width: 0;
left: 50%;
bottom: -0.0625rem;
position: absolute;
background: var(--secondaryGreen);
transition: left 0.28s ease, width 0.28s ease;
z-index: 2;
}
.form-group select,
.form-group input:focus,
.form-group input:valid,
.form-group input.form-file,
.form-group input.has-value,
.form-group textarea:focus,
.form-group textarea:valid,
.form-group textarea.form-file,
.form-group textarea.has-value {
color: #333;
}
.form-group select ~ .control-label,
.form-group input:focus ~ .control-label,
.form-group input:valid ~ .control-label,
.form-group input.form-file ~ .control-label,
.form-group input.has-value ~ .control-label,
.form-group textarea:focus ~ .control-label,
.form-group textarea:valid ~ .control-label,
.form-group textarea.form-file ~ .control-label,
.form-group textarea.has-value ~ .control-label {
font-size: 0.8rem;
color: gray;
top: -1rem;
left: 0;
}
.form-group select ~ .control-label {
top: -1.5rem;
}
.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus {
outline: none;
}
.form-group select:focus ~ .control-label,
.form-group input:focus ~ .control-label,
.form-group textarea:focus ~ .control-label {
color: var(--secondaryGreen);
}
.form-group select:focus ~ .bar::before,
.form-group input:focus ~ .bar::before,
.form-group textarea:focus ~ .bar::before {
width: 100%;
left: 0;
}
<div class="main">
<div class="title">Title</div>
<div>Details</div>
<div class="form-group">
<input type="text" id="feedName" name="name" value="" onChange={this.handleInputChange} />
<label class="control-label" htmlFor="feedName">Name</label>
<i class="bar"></i>
</div>
<div class="form-group">
<select id="feedKind" name="feedKind" onChange={this.handleInputChange}>
<option value="option 1">
Option 1
</option>
<option value="option 2">
Option 2
</option>
</select>
<label class="control-label" htmlFor="feedKind">Type</label>
<i class="bar"></i>
</div>