Mayuri Jadhav
Mayuri Jadhav

Reputation: 83

Want to expand the search input to the left

I am trying to expand the search box to the left but somehow it takes the width and expands to the right. I tried to give the margin-left but still it doesn't work.

Here it is expanding to right but i want it to expand to left. I tried adding padding left but it is getting affected inside the box and not outside it.

.search-click {
  border: 1px solid #ccc;
  outline: none;
  background-size: 22px;
  background-position: 13px;
  border-radius: 100px;
  width: 363px;
  height: 40px;
  padding: 21px;
  transition: all 0.5s;
  margin-top: 54px;
  text-overflow: ellipsis;
  position: relative;
  overflow: hidden;
  //margin-left: -410px;
}

.search-click:focus {
  width: 800px;
  padding-left: 20px;
}

.search-click input {
  background: transparent;
  border: 1px solid #ccc;
  outline: none;
  position: absolute;
  width: 300px;
  height: 50px;
  left: 0%;
  padding: 10px;
}
<input type="text" class="search-click" placeholder="Search ports, countries, international code port" />

Upvotes: 0

Views: 517

Answers (2)

Sachin Som
Sachin Som

Reputation: 1201

For width transition in left, I have changed input's position to right. Changed position: absolute and right: 0; top: 0.

.search-click {
  border: 1px solid #ccc;
  outline: none;
  background-size: 22px;
  background-position: 13px;
  border-radius: 100px;
  width: 100px;
  padding: 21px;
  transition: all 0.5s;
  text-overflow: ellipsis;
  overflow: hidden;
  text-align: left;
  position: absolute;
  right: 0;
  top: 0;
  margin: 1em;
}

.search-click:focus {
  width: 400px;
  padding-left: 20px;
}
<input type="text" class="search-click" placeholder="Search ports, countries, international code port" />

Upvotes: 2

Mac
Mac

Reputation: 94

If you want expand it from the right, just add text-align: end; in the .search-click.

Upvotes: 0

Related Questions