I'm attempting to dynamically adjust the hr element's length based on the length of the input element by using CSS.
Additionally, I'd like to incorporate an animation that triggers when the input is focused.
I came across a solution for the h2 element on stackoverflow: How to do it with h2 element
Here is the code snippet:
h2{
font-size:50px;
padding:0 25%;
text-align:center;
}
h2 hr{ width:100%;height:10px;background:#000;}
<h2>
This is a very big title
<hr />
</h2>
I tried implementing a similar approach for the input element, but without success.
My Attempted Code:
hr.underline {width: 0%;}
input.input:focus hr.underline{
left:0;
width:100%;
height:2px;
background-color:#17e13f;
border:none;
margin-top:5px;
margin-left:0;
margin-bottom:0px;
}
<div>
<label for="1">Input</label>
<input class="input" type="text" id="1">
<hr class="underline">
</input>
</div>
However, this method doesn't seem to be working as expected. Does anyone have suggestions on how to achieve this, or perhaps a better alternative?