The document provides instructions for creating a simple one-page website with multiple sections that can be navigated between using a menu. It describes adding basic HTML tags, creating sections and a navigation menu, linking the menu to sections, and adding CSS styling. JavaScript and jQuery are used to enable smooth scrolling between sections when menu items are clicked.
1 of 16
Download to read offline
More Related Content
How to Create simple One Page site
1. How to create a simple one page site
By Moneer Kamal
moneerKamalprog@gmail.com
2. First of all we need html page basic tags to start with
<!DOCTYPE html>
<html>
<head>
<title>scroll</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
</body>
</html>
3. Then we add our sections container Inside the body tag. This container
Will be a div with sections class and inside of it we add sections
tags with class section for each
<div class="sections">
<section class=section" id="section1">
<h1>Section1</h1>
</section>
<section class=section" id="section2">
<h1>Section2</h1>
</section>
<section class=section" id="section3">
<h1>Section3</h1>
</section>
</div>
4. To navigate between sections we need to add a menu
before our sections each item of this menu will lead us
to a different section and we will add our
menu in a header tag
<header>
<nav>
<ul>
<li><a href="#section1">section1</a></li>
<li><a href="#section2">section2</a></li>
<li><a href="#section3">section3</a></li>
</ul>
</nav>
</header>
5. Now our body tag should look like this:
<body>
<header>
<nav>
<ul>
<li><a href="#section1">section1</a></li>
<li><a href="#section2">section2</a></li>
<li><a href="#section3">section3</a></li>
</ul>
</nav>
</header>
<div class="sections">
<section id="section1">
<h1>Section1</h1>
</section>
<section id="section2">
<h1>Section2</h1>
</section>
<section id="section3">
<h1>Section3</h1>
</section>
</div>
</body>
7. Well our page dose not look like a one page site yet we
still need the style to make it look good and the jquery
to create the functionality for the menu so lets start styling
8. Personally I prefer to reset the values of the margins
and padding for my elements before I start styling
you can do so by yourselves or you can just download
some reset css file from the internet
h1,div,section,nav,ul,li,header,body
{
display: block;
margin: 0;
padding: 0;
}
9. Now we style the header and the body
Body , html
{
overflow: hidden;
/*we dont need the scroll we are going to use
the menu to scroll */
}
header
{
position: fixed;
top:0;
background: rgba(0,0,0,0.76);
height: 90px;
width:100%;
}
10. To complete our header we should style the menu
nav
{
width:100%;
}
nav ul li
{
float: left;
color: #fff;
margin-left: 30px;
margin-top: 20px;
}
a {
float: left;
color: #fff;
text-transform: uppercase;
text-decoration: none;
}
13. Now we can start adding our functionality but before we start coding
we should add the jquery library
<script type=text/javascript src=/slideshow/how-to-create-simple-onepage-site/47837135/"jquery.js"></script>
the next slide contains simple code for a plugin that will help
us scroll between the sections this code will be helpful
and reusable so keep it for the future.
15. Now we use our lovely plugin. for me the default values that
I added will suit me perfectly
$(document).ready(function(){
$('ul li a').click(function (e)
{
e.preventDefault();
var to=$(this).attr('href');
$('body,html').scrollTo(to);
});
});
Note: you can add the code in script tag or in a different file and include it