chirag satapara chirag satapara - 2 months ago 16
HTML Question

Center icon vertically next to text

I have tried below code to get desired output, how to display that lock in middle of that.

I have tried so many thing, which I found on SO, but nothing helpful.
I am not very experienced in CSS.

I want to display like this:

enter image description here



.inline-block {
display: inline-block;
}

.lock_image {
width: 30px;
height: 30px;
}

hr {
width: 250px;
margin: 0px;
bottom: 1px;
margin-bottom: 5px !important;
margin-top: 5px !important;
}

.title {
margin: 0px;
}

<div class="inline-block"><img src="https://image.ibb.co/f7sA2Q/icons8_Lock_50.png" alt="icons8_Lock_50" border="0" class="lock_image"></div>
<div class="inline-block">
<p class="title">Google Drive Integrated Email</p>
<hr>
<a class="mgl20" href="javascript:void(0);">xyz@gmail.com</a>
</div>




Answer Source

I added a wrapper around the content you had and made it a flexbox with vertical center alignment.

.wrapper {
  display: flex;
  align-items: center;
}

.inline-block {
  display: inline-block;
}

.lock_image {
  width: 30px;
  height: 30px;
}

hr {
  width: 250px;
  margin: 0px;
  bottom: 1px;
  margin-bottom: 5px !important;
  margin-top: 5px !important;
}

.title {
  margin: 0px;
}
<div class="wrapper">
  <div class="inline-block">
    <img src="https://image.ibb.co/f7sA2Q/icons8_Lock_50.png" alt="icons8_Lock_50" border="0" class="lock_image">
  </div>
  <div class="inline-block">
    <p class="title">Google Drive Integrated Email</p>
    <hr>
    <a class="mgl20" href="javascript:void(0);">xyz@gmail.com</a>
  </div>
</div>