Using HTML+Tailwind v3, you need to write a script to create a website with a beautiful design and layout in the style of an art gallery:
At the top in the center of the web page, create a stylish panel with 3 tabs inside
Tab 1 will be responsible for adding photos to the site with the following extensions (jpg, png, webp).
Tab 2 will be responsible for displaying all photos uploaded to the site.
Tab 3 will be responsible for displaying the current date (DD:MM:YYYY format) and time of day (HH:MM format).
Create a function that would allow me to view my uploaded photos in full size with one click of the left mouse button.
At the top on the right side inside each uploaded photo there should be a red button for complete removal from the site.
Assistant
Certainly! Below is the HTML code for your art gallery website using HTML and Tailwind CSS v3. This code includes the required functionalities:
Stylish Panel with 3 Tabs at the top center of the page.
Tab 1: Allows users to upload photos with extensions .jpg, .png, .webp.
Tab 2: Displays all uploaded photos with a red delete button on each photo.
Tab 3: Shows the current date (DD:MM:YYYY) and time (HH:MM).
Clicking on a photo opens it in full size.
Photos can be deleted using the red button on each photo.
Note: Make sure to include Tailwind CSS in your project. The easiest way is to include it via CDN.
Here is the complete code:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Art Gallery</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Tailwind Config -->
<script>
tailwind.config = {
theme: {
extend: {
colors: {
'art-gallery-bg': '#f5f5f5',
'art-gallery-primary': '#333',
}
}
}
}
</script>
</head>
<body class="bg-art-gallery-bg font-sans">
<!-- Panel with Tabs -->
<div class="container mx-auto mt-10">
<div class="flex justify-center">
<div class="bg-white shadow-md rounded-lg w-full md:w-2/3">
<!-- Tab Navigation -->
<div class="flex justify-center border-b">
<button id="tabUpload" onclick="openTab(event, 'uploadTab')"
class="tablink py-2 px-4 text-gray-600 hover:text-art-gallery-primary focus:outline-none border-b-2 border-transparent hover:border-art-gallery-primary">Upload
Photos</button>
<button id="tabGallery" onclick="openTab(event, 'galleryTab')"
class="tablink py-2 px-4 text-gray-600 hover:text-art-gallery-primary focus:outline-none border-b-2 border-transparent hover:border-art-gallery-primary">Gallery</button>
<button id="tabDateTime" onclick="openTab(event, 'dateTimeTab')"
class="tablink py-2 px-4 text-gray-600 hover:text-art-gallery-primary focus:outline-none border-b-2 border-transparent hover:border-art-gallery-primary">Date
& Time</button>
</div>
<!-- Tab Contents -->
<div id="uploadTab" class="tabcontent p-6">
<h2 class="text-xl font-semibold mb-4">Upload Photos</h2>
<input id="photoInput" type="file" accept="image/jpeg,image/png,image/webp" multiple
class="block w-full text-sm text-gray-600
file:mr-4 file:py-2 file:px-4
file:rounded-full file:border-0
file:text-sm file:font-semibold
file:bg-indigo-50 file:text-indigo-700
hover:file:bg-indigo-100
" />
<button onclick="uploadPhotos()"
class="mt-4 bg-indigo-600 text-white py-2 px-4 rounded hover:bg-indigo-700">Upload</button>
</div>
<div id="galleryTab" class="tabcontent p-6 hidden">
<h2 class="text-xl font-semibold mb-4">Gallery</h2>
<div id="gallery" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
<!-- Images will be displayed here -->
</div>
</div>
<div id="dateTimeTab" class="tabcontent p-6 hidden">
<h2 class="text-xl font-semibold mb-4">Current Date & Time</h2>
<p id="currentDate" class="text-lg"></p>
<p id="currentTime" class="text-lg"></p>
</div>
</div>
</div>
</div>
<!-- Full Size Image Modal -->
<div id="imageModal" class="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center hidden">
<div class="relative">
<img id="fullSizeImage" src="" alt="Full Size" class="max-w-full max-h-full" />
<button onclick="closeModal()"
class="absolute top-2 right-2 text-white text-3xl font-bold">×</button>
</div>
</div>
<!-- JavaScript -->
<script>
// Default to open Upload Tab
document.getElementById('tabUpload').classList.add('border-art-gallery-primary', 'text-art-gallery-primary');
document.getElementById('uploadTab').classList.remove('hidden');
function openTab(evt, tabId) {
// Hide all tab contents
const tabContents = document.querySelectorAll('.tabcontent');
tabContents.forEach(tabContent => {
tabContent.classList.add('hidden');
});
// Remove active classes from all tabs
const tabLinks = document.querySelectorAll('.tablink');
tabLinks.forEach(tabLink => {
tabLink.classList.remove('border-art-gallery-primary', 'text-art-gallery-primary');
});
// Show the selected tab content
document.getElementById(tabId).classList.remove('hidden');
// Add active class to the selected tab
evt.currentTarget.classList.add('border-art-gallery-primary', 'text-art-gallery-primary');
// If DateTime tab, update date and time
if (tabId === 'dateTimeTab') {
updateDateTime();
}
}
let uploadedPhotos = [];
function uploadPhotos() {
const input = document.getElementById('photoInput');
const files = input.files;
if (files.length === 0) {
alert('Please select one or more photos to upload.');
return;
}
for (let i = 0; i < files.length; i++) {
const file = files[i];
const reader = new FileReader();
reader.onload = function (e) {
uploadedPhotos.push(e.target.result);
displayPhotos();
}
reader.readAsDataURL(file);
}
// Clear the input
input.value = '';
// Switch to Gallery Tab
document.getElementById('tabGallery').click();
}
function displayPhotos() {
const gallery = document.getElementById('gallery');
gallery.innerHTML = '';
uploadedPhotos.forEach((photo, index) => {
const photoDiv = document.createElement('div');
photoDiv.classList.add('relative', 'group');
const img = document.createElement('img');
img.src = photo;
img.alt = `Photo ${index + 1}`;
img.classList.add('w-full', 'h-auto', 'cursor-pointer', 'rounded');
img.onclick = () => openModal(photo);
// Delete Button
const deleteBtn = document.createElement('button');
deleteBtn.innerHTML = '×';
deleteBtn.classList.add('absolute', 'top-2', 'right-2', 'bg-red-600', 'text-white', 'rounded-full', 'w-8', 'h-8', 'flex', 'items-center', 'justify-center', 'opacity-0', 'group-hover:opacity-100', 'transition', 'duration-200');
deleteBtn.onclick = () => deletePhoto(index);
photoDiv.appendChild(img);
photoDiv.appendChild(deleteBtn);
gallery.appendChild(photoDiv);
});
}
function openModal(photoSrc) {
const modal = document.getElementById('imageModal');
const fullSizeImage = document.getElementById('fullSizeImage');
fullSizeImage.src = photoSrc;
modal.classList.remove('hidden');
}
function closeModal() {
const modal = document.getElementById('imageModal');
modal.classList.add('hidden');
}
function deletePhoto(index) {
if (confirm('Are you sure you want to delete this photo?')) {
uploadedPhotos.splice(index, 1);
displayPhotos();
}
}
function updateDateTime() {
const date = new Date();
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months start at 0!
const year = date.getFullYear();
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
document.getElementById('currentDate').textContent = `Date: ${day}:${month}:${year}`;
document.getElementById('currentTime').textContent = `Time: ${hours}:${minutes}`;
}
// Update time every minute
setInterval(() => {
if (document.getElementById('dateTimeTab').classList.contains('hidden')) {
// Do nothing if DateTime tab is not visible
return;
}
updateDateTime();
}, 60000);
</script>
</body>
</html>
Explanation of the Code:
Tailwind CSS: Included via CDN for styling.
Panel with Tabs:
The panel is centered at the top using Flexbox.
The tabs are created using buttons with event listeners to switch between tabs.
Tab Contents:
Upload Tab:
Contains an <input> element for file selection, accepting .jpg, .png, and .webp files.
An "Upload" button triggers the uploadPhotos() function.
Gallery Tab:
Displays uploaded photos in a responsive grid.
Each photo has a red delete button at the top-right corner.
Date & Time Tab:
Shows the current date and time in the specified format.
The date and time are updated every minute using setInterval.
JavaScript Functions:
openTab(): Handles tab switching.
uploadPhotos(): Reads the selected files and displays them.
displayPhotos(): Updates the gallery with the uploaded photos.
openModal(): Opens a modal to display the clicked photo in full size.
closeModal(): Closes the full-size image modal.
deletePhoto(): Deletes a photo from the gallery.
updateDateTime(): Updates the date and time display.
Usage Instructions:
Upload Photos:
Click on the "Upload Photos" tab.
Select images to upload (you can select multiple images at once).
Click the "Upload" button.
The photos will appear in the "Gallery" tab.
View Photos:
Click on the "Gallery" tab.
Click on any photo to view it in full size.
Click on the close button (×) to close the full-size view.
Delete Photos:
In the "Gallery" tab, hover over a photo to reveal the red delete button at the top-right corner.
Click the delete button to remove the photo.
View Date & Time:
Click on the "Date & Time" tab to view the current date and time.
The time updates every minute.
Important Notes:
Data Persistence: The uploaded photos are stored in the uploadedPhotos array in JavaScript memory. This means that if you refresh the page, the uploaded photos will be lost. For persistent storage, consider using localStorage or setting up a backend server.
Browser Support: Ensure that you are using a modern browser that supports the FileReader API and ES6 features.
Styling: You can further customize the styling by modifying the Tailwind classes or adding your own CSS.
I hope this meets your requirements! If you have any questions or need further customization, feel free to ask.