Solution 1 :

Wrap search input with div and define text-align:center on wrapped div.
Follow below snippet:

.input-wrap{
  text-align: center;
}	
#searchbar{
  background: #FFF;
  padding: 1px 1px 1px 5px;
  position: relative; top: 0; left: 0;
  width: 178px;
  height: 21px;
  outline: none;
  border: 1px solid #CCCCCC;
  -webkit-transition: all .5s;
  -moz-transition: all .5s;
  transition: all .5s;
  text-align: center;
}
#searchbar:focus{
  width: 100%;
  width: 300px;
}
<div class="input-wrap">
  <input type="text" name="search" id="searchbar" placeholder="Search">
</div>

Solution 2 :

I have edited your code. check it.

#searchbar{
  margin-left: 50px;
  background: #FFF;
  padding: 1px 1px 1px 5px;
  position: relative; top: 0; left: 0;
  width: 178px;
  height: 21px;
  font-size: 12px;
  outline: none;
  border: 1px solid #CCCCCC;
  -webkit-transition: all .5s;
  -moz-transition: all .5s;
  transition: all .5s;
}

#searchbar:focus{
  background: #FFF;
  padding: 1px 1px 1px 5px;
  height: 21px;
  border: 1px solid #CCCCCC;
  top: 0;
  right: 100%; 
  font-size: 14px;
  transform: scalex(1.2);
  font-stretch: ultra-condensed;
}
<div class="input-wrap">
  <input type="text" name="search" id="searchbar" placeholder="Search">
</div>

Solution 3 :

I would recommend using the scaleX transformation which will handle allow expanding on both sides.

scaleX => Defines a scale transformation by giving a value for the X-axis

#searchBar:focus{
   .
   .
   .
   transform:scaleX(scaleValue);
}

Problem :

I have an input bar with the css below. Every time it is selected it is supposed to expand. However, it only expands to the left side and not to the right side. (I want it to expand on the right side) This is probably a duplicate so if it is, please mark it as one. However, I just could not find anything that tells me how to do this?

html:

<input placeholder = "search something up"id = "searchbar" name = "search">

css:

#searchbar{
  margin-left: 10px;
  background: #FFF;
  padding: 1px 1px 1px 5px;
  position: relative; top: 0; left: 0;
  width: 178px;
  height: 21px;
  outline: none;
  border: 1px solid #CCCCCC;

  -webkit-transition: all .5s;
  -moz-transition: all .5s;
  transition: all .5s;
}

#searchbar:focus{
  width: 100%;
  background: #FFF;
  padding: 1px 1px 1px 5px;
  width: 300px;
  height: 21px;
  border: 1px solid #CCCCCC;
  top: 0;
  right: 100%; 
}

Comments

Comment posted by Akhil Aravind

Try to post code with both html and css, so that we can easily reproduce the markups.

Comment posted by AmerllicA

Welcome to Stack Overflow, I leave an upvote to your post for your motivation.

Comment posted by John Kitonyo

@coolpigeon2122 Looks okay to me but in the meantime try removing the two width declarations in the ::focus and check if you will need a position too in the ::focus and off-course html would have been helpful.

Comment posted by Zuber

The only problem is the text are getting stretched on focus because of

Comment posted by Saeed Jamali

I have edited the answer to fix the stretch issue. you can wotk with font size and font-stretch property to minimize the stretching issue. hope it helps.

By