One-Page Website with Fixed Floating Bottom Navigation using HTML, CSS & JavaScript [Source Code]
To make this website, you would like to make three files: an HTML file, a CSS file & a JavaScript file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.
* {
margin: 0;
padding: 0;
}
nav {
position: fixed;
bottom: 20px;
width: 40%;
background: #000000;
background: -webkit-linear-gradient(to right, #434343, #000000);
background: linear-gradient(to right, #434343, #000000);
margin: 10px 30%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
border-radius: 50px;
}
nav ul {
list-style: none;
text-align: center;
height: 100%;
}
nav ul li {
display: inline-block;
height: 100%;
}
nav ul li a {
display: inline-block;
color:#fff;
text-align: center;
padding: 16px;
text-decoration: none;
font-size: 20px;
height: 100%;
font-weight: 900;
font-family: 'Aladin', cursive;
}
@media only screen and (max-width: 860px) {
nav
{
width:60%;
margin: 10px 20%;
}
}
@media only screen and (max-width: 600px) {
nav
{
width:80%;
margin: 10px 10%;
}
nav ul li a{
font-size: 17px;
padding: 8px;
}
}
section {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#home {
background: #12c2e9; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #f64f59, #c471ed, #12c2e9); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #f64f59, #c471ed, #12c2e9);
}
#about {
background: #FDC830; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #F37335, #FDC830); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #F37335, #FDC830); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
#services {
background: #ec008c; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #fc6767, #ec008c); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #fc6767, #ec008c); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
#contact {
background: #00c3ff; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #ffff1c, #00c3ff); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #ffff1c, #00c3ff); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
h1 {
margin-bottom: 20px;
font-size: 98px;
color:#000;
text-shadow: 3px 3px 0px #fff;
font-family: 'Aladin', cursive;
}
p {
font-size: 24px;
color: #333;
}
@media only screen and (max-width: 860px) {
h1
{
font-size: 38px;
}
p{
font-size: 12px;
}
}
@media only screen and (max-width: 600px) {
h1
{
font-size: 38px;
}
p{
font-size: 12px;
}
}
.credit a {
text-decoration: none;
color: #fff;
font-weight: 800;
}
.credit {
color: #fff;
text-align: center;
margin-top: 10px;
font-family: Verdana,Geneva,Tahoma,sans-serif;
}
let navLinks = document.querySelectorAll('nav a');
let sections = document.querySelectorAll('section');
navLinks.forEach(link => {
link.addEventListener('click', e => {
e.preventDefault();
const target = document.querySelector(link.getAttribute('href'));
const targetTop = target.offsetTop;
window.scrollTo({
top: targetTop,
behavior: "smooth"
});
});
});
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (pageYOffset >= (sectionTop - sectionHeight / 3)) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href').includes(current)) {
link.classList.add('active');
}
});
});
Thank you for reading our blog. If you face any problem in creating this One-Page Website with Fixed Floating Bottom Navigation using HTML, CSS & JavaScript, then contact us or comment to us. We’ll try to provide a solution to your problem as soon as possible.
Explore
Press The Key ' p ' and say ' read article ' our voice assistant read our article.
In Our older post it doesnot work we working on that.
In Our older post it doesnot work we working on that.
إرسال تعليق
Thank you
Learning robo team