Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animated Search Form expanding to the left

Tags:

html

css

My box is expanding to the right, how can I make it expand to the left?

 input[type=text] {
        width: 130px;
        box-sizing: border-box;
        border: 2px solid #ccc;
        border-radius: 4px;
        font-size: 16px;
        background-color: white;
        background-image: url('searchicon.png');
        background-position: 10px 10px; 
        background-repeat: no-repeat;
        padding: 12px 20px 12px 40px;
        -webkit-transition: width 0.4s ease-in-out;
        transition: width 0.4s ease-in-out;
    }
    
    input[type=text]:focus {
        width: 100%;
    }
    
<form>
      <input type="text" name="search" placeholder="Search..">
    </form>

1 Answers

Just align it to the right of its container element. Either change the display attribute to block and set the right and left margins to 0 and auto, or keep it as an inline element and apply text-align: right to the container block.

input[type=text] {
  display:block;
  margin: 0 0 0 auto;
  width: 130px;
  box-sizing: border-box;
  border: 2px solid #ccc;
  border-radius: 4px;
  font-size: 16px;
  background-color: white;
  background-image: url('searchicon.png');
  background-position: 10px 10px;
  background-repeat: no-repeat;
  padding: 12px 20px 12px 40px;
  -webkit-transition: width 0.4s ease-in-out;
  transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
  width: 100%;
}
<form>
  <input type="text" name="search" placeholder="Search..">
</form>
like image 148
r3mainer Avatar answered Jan 27 '26 07:01

r3mainer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!