Sure! Below is the code for a modern, stylish, and fully functional HTML page about countries. This page features an interactive world map where users can click on a country to view information about it. The design is responsive and incorporates modern CSS styling.
Instructions:
- Copy the code below into a file and save it with an
.html extension (e.g., countries.html).
- Open the file in a web browser to view the page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>World Countries Interactive Map</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Include a modern CSS reset -->
<style>
/* CSS Reset */
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* Styling for the page */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f0f2f5;
color: #333;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
background-color: #4b79a1;
color: white;
padding: 20px;
text-align: center;
}
h1 {
margin-bottom: 10px;
}
main {
flex: 1;
display: flex;
flex-direction: row;
padding: 20px;
}
#map {
flex: 2;
margin-right: 20px;
}
#info {
flex: 1;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
#info h2 {
margin-bottom: 15px;
}
footer {
background-color: #4b79a1;
color: white;
text-align: center;
padding: 10px;
}
/* Responsive Design */
@media (max-width: 768px) {
main {
flex-direction: column;
}
#map, #info {
margin-right: 0;
margin-bottom: 20px;
}
}
</style>
<!-- Include a JavaScript library for the interactive map -->
<script src="https://unpkg.com/svgmap@latest/dist/svgMap.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/svgmap@latest/dist/svgMap.min.css">
</head>
<body>
<header>
<h1>Explore the Countries of the World</h1>
<p>Click on a country to learn more about it.</p>
</header>
<main>
<div id="map"></div>
<div id="info">
<h2>Country Information</h2>
<p>Select a country on the map to see details here.</p>
</div>
</main>
<footer>
© 2023 World Countries Interactive Map
</footer>
<!-- JavaScript for interactive functionality -->
<script>
// Sample data for countries
const countryData = {
US: {
countryName: 'United States',
capital: 'Washington, D.C.',
population: '331 million',
language: 'English',
currency: 'US Dollar (USD)'
},
CA: {
countryName: 'Canada',
capital: 'Ottawa',
population: '38 million',
language: 'English, French',
currency: 'Canadian Dollar (CAD)'
},
// ... Add more countries as needed
};
// Initialize the SVG map
new svgMap({
targetElementID: 'map',
data: {
data: {},
applyData: 'data',
},
mouseWheelZoomEnabled: false,
onClick: (countryCode) => {
const infoDiv = document.getElementById('info');
const countryInfo = countryData[countryCode];
if (countryInfo) {
infoDiv.innerHTML = `
<h2>${countryInfo.countryName}</h2>
<p><strong>Capital:</strong> ${countryInfo.capital}</p>
<p><strong>Population:</strong> ${countryInfo.population}</p>
<p><strong>Language(s):</strong> ${countryInfo.language}</p>
<p><strong>Currency:</strong> ${countryInfo.currency}</p>
`;
} else {
infoDiv.innerHTML = `
<h2>Information Unavailable</h2>
<p>We don't have information about this country yet.</p>
`;
}
}
});
</script>
</body>
</html>
Explanation:
- The HTML code uses a library called SVGMap to display an interactive world map.
- When a user clicks on a country, the
onClick event handler retrieves information about that country from the countryData object and displays it in the #info div.
- The page uses modern CSS features like Flexbox for responsive design and includes a CSS reset for consistency.
- The design is made to be clean and modern, with a focus on usability and aesthetics.
Notes:
- The
countryData object currently contains sample data for the United States and Canada. You can expand this object by adding more countries following the same format.
- The SVGMap library is included via CDN links in the
<head> section. Ensure you have an internet connection to load these resources, or you can download them and host locally if needed.
- The page is responsive and will adjust its layout on smaller screens, thanks to the media queries in the CSS.
Customization:
- To add more countries, simply add more entries to the
countryData object using the country's ISO code as the key.
- You can customize the styling by modifying the CSS in the
<style> tags.
- Feel free to enhance the functionality by adding features like search, filters, or additional data points.
Enjoy your interactive exploration of world countries!