a website for study calendar only using html css js tailwind bootstrap php json
Creating a simple study calendar website using HTML, CSS, JavaScript, Tailwind CSS, Bootstrap, PHP, and JSON involves several steps. Below is a basic outline of how you can set this up, along with example code snippets.
/study-calendar
├── index.html
├── style.css
├── script.js
├── calendar.php
├── data.json
index.html
This is the main HTML file that will display the calendar.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Study Calendar</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body class="bg-gray-100">
<div class="container mx-auto mt-10">
<h1 class="text-3xl font-bold text-center">Study Calendar</h1>
<div id="calendar" class="mt-5"></div>
</div>
<script src="script.js"></script>
</body>
</html>
style.css
You can add custom styles here if needed.
/* Custom styles can go here */
script.js
This JavaScript file will handle fetching the calendar data and rendering it.
document.addEventListener('DOMContentLoaded', function() {
fetch('calendar.php')
.then(response => response.json())
.then(data => {
const calendarDiv = document.getElementById('calendar');
data.forEach(event => {
const eventDiv = document.createElement('div');
eventDiv.className = 'bg-white p-4 m-2 rounded shadow';
eventDiv.innerHTML = `<h2 class="font-bold">${event.title}</h2><p>${event.date}</p><p>${event.description}</p>`;
calendarDiv.appendChild(eventDiv);
});
})
.catch(error => console.error('Error fetching calendar data:', error));
});
calendar.php
This PHP file will read the JSON data and return it.
<?php
header('Content-Type: application/json');
$data = file_get_contents('data.json');
echo $data;
?>
data.json
This JSON file will contain the events for the calendar.
[
{
"title": "Math Exam",
"date": "2023-10-15",
"description": "Prepare for the upcoming math exam."
},
{
"title": "Science Project Due",
"date": "2023-10-20",
"description": "Submit the science project."
},
{
"title": "History Presentation",
"date": "2023-10-25",
"description": "Present the history project in class."
}
]
index.html
through your web server (e.g., http://localhost/study-calendar/index.html
).calendar.php
, which reads from data.json
.