Basic Structure
- HTML: Create a structure for your book reviews.
- CSS: Style the site to make it visually appealing.
- JavaScript: Add interactivity, such as adding and displaying reviews.
Step 1: HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Review Site</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Book Review Site</h1>
<form id="reviewForm">
<input type="text" id="bookTitle" placeholder="Book Title" required>
<textarea id="bookReview" placeholder="Write your review here..." required></textarea>
<button type="submit">Submit Review</button>
</form>
<div id="reviewsContainer">
<h2>Reviews:</h2>
<ul id="reviewsList"></ul>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Step 2: CSS
Create a file named styles.css
to style your site.
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1, h2 {
color: #333;
}
form {
margin-bottom: 20px;
}
input[type="text"], textarea {
width: 100%;
padding: 10px;
margin: 5px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
background-color: #28a745;
color: white;
padding: 10px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #218838;
}
#reviewsList {
list-style-type: none;
padding: 0;
}
.review {
background: #f9f9f9;
padding: 10px;
margin: 5px 0;
border-radius: 4px;
}
Step 3: JavaScript
Create a file named script.js
to handle the review submissions and display.
document.getElementById('reviewForm').addEventListener('submit', function(event) {
event.preventDefault();
const bookTitle = document.getElementById('bookTitle').value;
const bookReview = document.getElementById('bookReview').value;
const reviewList = document.getElementById('reviewsList');
const reviewItem = document.createElement('li');
reviewItem.classList.add('review');
reviewItem.innerHTML = `<strong>${bookTitle}</strong><p>${bookReview}</p>`;
reviewList.appendChild(reviewItem);
// Clear the form
document.getElementById('reviewForm').reset();
});
Putting It All Together
- Folder Structure:
- Create a folder for your project.
- Inside that folder, create three files:
index.html
,styles.css
, andscript.js
.
- Open the HTML: Open
index.html
in your web browser to see your book review site in action!
Future Enhancements
- Backend Integration: Use a backend service to store reviews permanently.
- User Authentication: Allow users to create accounts and save their reviews.
- Rating System: Implement a star rating system for reviews.
- Search Functionality: Enable searching for books and reviews.
Leave a Reply