I'm trying to center a header text on a header background image using HTML and CSS.
I set the background image in the header class:
.header {
background-image: url("https://s3.amazonaws.com/codecademy-content/courses/web-101/unit-6/htmlcss1-img_burgerphoto.jpeg");
background-position: center;
background-size: cover;
height: 320px
}
And then manipulate the text in a .header h1
:
.header h1 {
background-color: #05A8AA;
color: #FFF;
font-family: 'Oswald', sans-serif;
font-size: 40px;
font-weight: 300;
line-height: 40px;
width: 68%;
padding: 20px;
margin: 0 auto;
}
If I add to the second code block, the quality position: relative;
, then I can manipulate top
to achieve my goal.
My confusion is, when I adjust the margin-top
property in .header h1
, it shifts the entire header, including the background image down, instead of moving the h1
text down on the background image.
My question is why? Why does adjusting the margin of the h1
header element, instead move the entire image?