Centering input box and icon button

Lan Mai

I want to center vertically both of the input box and the icon button. I tried flexbox justify-content and align-content and it still not working. Is there any way in css that i can do this? Thank you.

ab29007

You have to wrap them with a container div which will have display:flex;. It is always good to use flex-direction property, in your case that would be row.

Then to align the items vertically use align-item:center;. And if you want them to be horizontally centered as well then add justify-content:center; to the css of .container in the example below.

I have used an image as well as a font-awesome icon for search-icon alongside the input box, Since you have not mentioned in the question which one you are using.

.container{
  display:flex;
  flex-direction:row;
  align-items:center;
}
.container input{
  line-height:80px;
  margin:0 5px;
}
.container img{
  height:50px;
  margin:0 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="container">
  <input type="text" placeholder="Search"/>
  <i class="fa fa-search"></i>
  <img src="http://www.chinabuddhismencyclopedia.com/en/images/thumb/b/b8/Nature.jpg/240px-Nature.jpg">
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Overlay icon on input box

From Dev

vertical and horizontal centering datalist box with its button

From Dev

Centering email input and button using Bootstrap

From Dev

Icon on AngularJS input type button

From Dev

Centering a button

From Dev

Centering an icon in SVG

From Dev

Qt - Centering Icon in QTreeWidgetItem

From Dev

Qt - Centering Icon in QTreeWidgetItem

From Dev

Centering icon with text

From Dev

Bootstrap button icon on type input submit not visible

From Dev

Font awesome icon and text in input submit button?

From Dev

How to add Font Awesome icon into <input> button?

From Dev

Laravel Form: Input Button Not Showing HTML Icon

From Dev

Bootstrap button icon on type input submit not visible

From Dev

Flexbox centering in a box

From Dev

Placing a Input Box over a Button with same width

From Dev

Submit Button only saves one input box

From Dev

change style of button on focus of input box

From Dev

Adding a popover to an input box with a button (angularJS)

From Dev

How create an input box having a + and - button in Ionic

From Dev

Submit Button only saves one input box

From Dev

Append text of the input box on radio button clicked

From Dev

Add a cancel button to input box VB

From Dev

Edit button on GridView not updating with input box data

From Dev

Input box value is showing blank on button click

From Dev

Using paper-icon-button as input button to submit a form

From Dev

Using paper-icon-button as input button to submit a form

From Dev

jQuery Datepicker icon showing below the input box instead of on the right

From Dev

Clear icon inside input text box angular way