Home > Enterprise >  Want to expand the search input to the left
Want to expand the search input to the left

Time:12-29

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"  placeholder="Search ports, countries, international code port" />

CodePudding user response:

You can do this by using direction: rtl

.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;
  direction: rtl;
}

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

CodePudding user response:

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;
  position: relative;
  overflow: hidden;
  text-align: left;
  position: absolute;
  right: 0;
  top: 0;
  margin: 1em;
}

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

CodePudding user response:

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

  • Related