<form onsubmit="event.preventDefault();" class="search-form">
<label for="search" class="screen-reader-text">Search</label>
<input id="search"
type="search" class="search-input" placeholder="Enter search terms..." required>
<button class="search-button">Search</button>
</form>
.search-form {
--searchButtonWidth: 75px;
max-width: 320px;
margin: 0 auto;
overflow: hidden;
position: relative;
}
.search-input {
border: 0;
margin: 0;
padding: 0.5rem calc(var(--searchButtonWidth) + 0.5rem) 0.5rem 0.5rem;
border-radius: 8px;
width: 100%;
background: #ddd;
-webkit-appearance: none;
font-size: 13px;
}
.search-input:focus {
outline: 0;
background: white;
}
.search-input:valid ~ .search-button {
transform: translateX(calc(-1 * var(--searchButtonWidth)));
}
.search-button {
border: 0;
padding: 0.5rem;
border-radius: 8px;
position: absolute;
top: 0;
left: 100%;
width: var(--searchButtonWidth);
transition: 0.2s;
background: #455A64;
color: white;
font-size: 13px;
height: 100%;
}
.search-button:focus {
outline: 0;
background: #222;
}
body {
margin: 2rem;
background: #888;
}
.screen-reader-text {
position: absolute;
top: -9999px;
left: -9999px;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.