-1

I am trying to add an image next to a text inside a header but the image is over the padding.

jsfiddle

body {
  margin: 0;
  padding: 0;
}

header {
  width: 95%;
  margin: 10px auto;
  padding: 20px;
  border-radius: 8px;
  box-sizing: border-box;
  background-color: blue;
}
<body>
  <header>
    <img src="http://www.symbols.com/gi.php?type=1&id=3005" style="width: 50px; height: 50px">
    <h1 style="display: inline-block;">
      Hi!
    </h1>
  </header>
</body>

I need them to be vertically aligned together, and the image to stop being on top of the padding.

This is different than other examples here on stackoverflow because here Im working with paddings.

Chormi
  • 13
  • 1
  • 6

2 Answers2

1

You can use Flex to make the text adjacent to the image:

div {
  display: flex;
  align-items: center;
}
header {
  width: 95%;
  margin: 10px auto;
  padding: 20px;
  border-radius: 8px;
  box-sizing: border-box;
  background-color: white;
}
<div>
  <img src="http://www.symbols.com/gi.php?type=1&id=3005" style="width: 50px; height: 50px">
  <h1>Hi!</h1>
</div>

Read more about Flex here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

The Codesee
  • 3,714
  • 5
  • 38
  • 78
-1

Try to add this to you css file:

h1 {margin-top:10px;}

and add "align=left" to

<img src = "http://www.symbols.com/gi.php?type=1&id=3005" style="width: 50px; height: 50px" align="left">
randomz
  • 1
  • 3