I have a fixed header with variant height and the reason for that is the promotion bar that you can see in the preview which is a part of the header.
Now since the rule of the HTML says "It's normal behavior. Give some calculated top margin to your content" so that the content which is hidden under the fixed header will come down.
Now the issue is since I have a variant header height, I can't put a definitive margin-top to the content, and it's because if you close the promotion bar the gap between the header and the content is "too much" and if I don't close the promotion bar which is a default behavior the margin will be completely different.
What are the ways to tackle this issue?
$('div.promotion div.float-right').on('click', function(e) {
//$(this).closest('div.top-head.fixed-top').hide();
// or, if you need to remove it
$('.promotion').remove();
});
.promotion {
background: #02b875;
width: 100%;
float: left;
height: 38px;
color: #FFF;
padding: 8px;
letter-spacing: 0.2px;
font-size: 15px;
}
.promotion-code {
font-weight: 600;
}
.close-promotion {
cursor: pointer;
}
.top-head {
border-bottom: 1px solid rgba(0, 0, 0, 0.12);
background: #FFFFFF;
width: 100%;
float: left;
height: 50px;
padding: 10px;
position: fixed;
}
.content {
margin-top: 80px;
padding: 20px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css">
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="fixed-top">
<div class="promotion">
<div class="container container-responsive">
Get £20 off on your first trip. Enter <span class="promotion-code">WELCOME20</span> at checkout.
<div class="close-promotion float-right"><i class="fas fa-times"></i></div>
</div>
</div>
<div class="top-head">
<div class="container container-responsive">
Hello world
</div>
</div>
</div>
<div class="content">
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
Content<br>
</div>