I am seeking a solution to prevent a div from moving up on mobile devices with smaller widths. While I understand that this can be achieved with media queries, I am curious if there is a more elegant approach.
.wrapper {
background: no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
padding-top: 23%;
overflow: hidden;
text-align: center;
}
#titlebackground {
background: rgba(0, 0, 0, .5);
}
#title {
font-family: Consolas, monaco, monospace;
text-align: center;
font-size: 5em;
font-weight: 900;
color: #fff;
display: inline-block;
}
#titlelocation {
position: relative;
top: -50px;
}
<header>
<div class="wrapper">
<div id="titlelocation">
<div id="titlebackground">
<span id="title">My Title</span>
</div>
</div>
</div>
</header>
Is there a way to elevate the title above the center of the div without it moving further up at lower resolutions?
Edit: To replicate the issue, run the code snippet in full screen and then adjust the screen width. The div will move upwards as the screen size decreases.