I understand that you want to add advanced functionality without relying on libraries, frameworks, or backends. Here's an updated version of the HTML layout with some pure CSS and JavaScript features that enhance the appearance and interactivity:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced HTML Layout</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #333;
padding: 1rem;
}
header h1 {
color: white;
margin: 0;
}
nav {
background-color: #555;
}
nav ul {
list-style-type: none;
padding: 0;
display: flex;
justify-content: space-around;
}
nav li {
display: inline;
}
nav a {
color: white;
text-decoration: none;
padding: 1rem;
display: block;
}
nav a:hover {
background-color: #777;
}
main {
display: flex;
justify-content: space-around;
padding: 2rem;
}
section {
width: 45%;
background-color: #f0f0f0;
padding: 1rem;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.15);
}
footer {
background-color: #333;
color: white;
text-align: center;
padding: 1rem;
}
</style>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<main>
<section id="about">
<h2>About Us</h2>
<p>Here is some information about our company.</p>
</section>
<section id="services">
<h2>Services</h2>
<p>Here is a description of our services.</p>
</section>
</main>
<footer>
<p>My Website © 2022</p>
</footer>
<script>
// Change section background color on click
const aboutSection = document.getElementById("about");
const servicesSection = document.getElementById("services");
const backgroundColors = ["#f0f0f0", "#add8e6", "#ffd700", "#90ee90"];
function changeBackgroundColor(element) {
const currentColorIndex = backgroundColors.indexOf(element.style.backgroundColor);
const nextColorIndex = (currentColorIndex + 1) % backgroundColors.length;
element.style.backgroundColor = backgroundColors[nextColorIndex];
}
aboutSection.addEventListener("click", function() {
changeBackgroundColor(aboutSection);
});
servicesSection.addEventListener("click", function() {
changeBackgroundColor(servicesSection);
});
</script>
</body>
</html>
This example includes:
- A pure CSS style block added within the
<head> tag for styling elements.
- Responsive design achieved using percentage-based widths and the flexbox layout.
- A JavaScript script block for adding interactivity. In this case, when the user clicks on the 'About Us' or 'Services' sections, their background colors will cycle through a predefined array of colors without relying on any libraries or frameworks.
Keep in mind that using pure JavaScript and CSS within your HTML file can limit the advanced functionality possible without libraries, frameworks, or backends.