Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align image and text properly in HTML

Tags:

html

css

This is the example: enter image description here

I want to align the image along side with the name but somehow the image just floats up a little higher. Any help?

UPDATE:

#profile_name_header {
  background-color: #006400;
  font-family: Century Gothic;
  color: #FFFFFF;
  font-size: 20px;
  padding-bottom: 12px;
  padding-top: 12px;
  padding-left: 10px;
}
<div id="profile_name_header">
  <img src=< ?php echo "./img/".$genderprofile. ""; ?> style = "height:30px; margin-bottom:0px;" >
  <?php echo $fullname;  ?>'s Profile
</div>

Thank you.

like image 466
Dranreb Avatar asked Oct 26 '25 10:10

Dranreb


1 Answers

Use vertical-align on the img since it's adjacent inline content.

img {
    vertical-align: middle;
}
<img src="https://lh4.googleusercontent.com/-EK1g7sBpX74/AAAAAAAAAAI/AAAAAAAAABU/AzsjRnL3mKk/photo.jpg?sz=32"> @Dranreb

A fancier way is to use flexbox, but it's overkill for your use case. If you wanted to do that, just give them a parent, and use align-items to affect vertical alignment.

div {
  display: flex;
  align-items: center;
}
<div>
  <img src="https://lh4.googleusercontent.com/-EK1g7sBpX74/AAAAAAAAAAI/AAAAAAAAABU/AzsjRnL3mKk/photo.jpg?sz=32"> @Dranreb
</div>
like image 169
Michael Coker Avatar answered Oct 29 '25 01:10

Michael Coker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!