JSFiddle - React, Tailwind, and code Playground
by velo_ninja
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Parent div */
.parent-div {
display: flex;
align-items: center;
justify-content: flex-end;
position: relative;
width: 300px;
height: 30px;
border: 1px solid #333;
background-color:lightgrey;
}
/* Input field */
.input-field {
height: 85%;
width: 90%;
background-color: white;
border: 2px solid #999;
z-index: 2; /* Above the button */
position: relative;
padding-left: 20px; /* Space for the button */
}
.parent-div:hover {
background-color:yellow;
}
.parent-div:hover .input-field {
width: 80%; /* Shrink to 80% */
}
/* Button */
.button {
position: absolute;
left: 5px;
width: 20px;
height: 20px;
background-color: red;
z-index: 1; /* Below the input */
border: none;
cursor: pointer;
}
</style>
<title>Layered Input and Button with Flexbox</title>
</head>
<body>
<div class="parent-div">
<button class="button"></button>
<input type="text" class="input-field" placeholder="Type here">
</div>
</body>
</html>