Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Image next to header text respect parent size

Im trying to add an image/logo next to my header text, and make sure the image keeps it aspect ratio, and respects the size of the container, which is as high as its containing text.
But the image keep overflowing, or using its real dimensions. How can I get the image next to the text, both text and image horizontally centered.
The parent div can not have a height set, as it should respect the size of the text.
I tried using table instead, I tried using a before: pseudo element, but nothing works. This is what i got at the moment and its so wrong

.batman {
  font-size: 20px;
  font-weight: bold;
  display: inline-block;
  width: 100%;
}

.batman img {
  min-width: 100%;
  min-height: 100%;
}
<div class="batman">
  <img src="https://i.imgur.com/JSWi9SB.png" /> title goes here
</div>

jsfiddle: https://jsfiddle.net/sxd91gqc/

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since it’s one line of text, define a height equal to the line-height:

.batman {
  font-size: 20px;
  font-weight: bold;
  display: inline-block;
  line-height: 1.2em;
  border: 1px solid red;
}

.batman img {
  height: 1.2em;
  vertical-align: middle;
}
<div class="batman">
  <img src="https://i.imgur.com/JSWi9SB.png" /> title goes here
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading