I'm having problems with JQuery.
The thing is that i want the height of a (div) header
as margin-top
of a div
which its class is "content", because otherwise, the div appears under the header.
Here you have the code:
Part of the HTML
<head>
/*whatever it's inside*/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<script>
$(document).ready(function(){
var 1 = $(".header").height() + "px");
$(".content").css ('margin-top', 1);
});
</script>
<body>
<div class="header">
<div class="container">
<div class="logo">
<h1><a href="#">Web</a></h1>
</div>
<div class="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="content">
<p>Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Curabitur blandit tempus porttitor. Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
</p>
</div>
</div>
</body>
</html>
Part of CSS
body {
width: 100%;
margin: auto;
}
.container {
width: 70%;
margin: 0 auto;
}
.header {
background: #6396bc;
width: 100%;
top: 0;
position: fixed;
}
.content {
margin-top: 200px;
}
I just put what is useful.
You have the JS in the HTML. Thanks in advance.