Create me a sandwich gallery viewer
- User
Create me a sandwich gallery viewer
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Create me a sandwich gallery viewer
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Sure, I'd be happy to help you create a "sandwich gallery viewer"! I'll interpret this as a fun, simple web application where you can browse a gallery of sandwich images. Since sandwiches are a delightful topic, I'll build a basic HTML, CSS, and JavaScript web page that displays a grid of sandwich images with captions. You can click on an image to view it larger in a simple lightbox effect.
I'll provide the complete code below, which you can copy and paste into your own files to run it. You'll need a basic text editor (like VS Code) and a web browser to test it. For the images, I'm using placeholder URLs from a free service (like placeholder.com) to simulate sandwich photos. In a real scenario, you could replace these with actual image URLs from a site like Unsplash or your own uploads.
To use this:
index.html, styles.css, and script.js.index.html in a web browser to see the gallery..item div in the HTML and change the image source and caption.Here's the code:
index.html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sandwich Gallery Viewer</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Sandwich Gallery Viewer</h1>
<div class="gallery">
<!-- Sandwich items go here -->
<div class="item" data-src="https://via.placeholder.com/600x400?text=BLT+Sandwich">
<img src="https://via.placeholder.com/300x200?text=BLT+Sandwich" alt="BLT Sandwich">
<p>BLT Sandwich: Bacon, Lettuce, and Tomato – a classic favorite!</p>
</div>
<div class="item" data-src="https://via.placeholder.com/600x400?text=Club+Sandwich">
<img src="https://via.placeholder.com/300x200?text=Club+Sandwich" alt="Club Sandwich">
<p>Club Sandwich: Layers of turkey, bacon, and veggies – stacked high!</p>
</div>
<div class="item" data-src="https://via.placeholder.com/600x400?text=Grilled+Cheese+Sandwich">
<img src="https://via.placeholder.com/300x200?text=Grilled+Cheese+Sandwich" alt="Grilled Cheese Sandwich">
<p>Grilled Cheese Sandwich: Gooey cheese and golden bread – comfort food at its best!</p>
</div>
<div class="item" data-src="https://via.placeholder.com/600x400?text=Veggie+Sandwich">
<img src="https://via.placeholder.com/300x200?text=Veggie+Sandwich" alt="Veggie Sandwich">
<p>Veggie Sandwich: Fresh veggies, hummus, and whole grain bread – healthy and tasty!</p>
</div>
<!-- Add more sandwiches here by copying and modifying a div.item element -->
</div>
<!-- Lightbox overlay -->
<div id="lightbox" class="lightbox">
<span class="close">×</span>
<img class="lightbox-content" id="lightbox-img">
<div id="caption"></div>
</div>
<script src="script.js"></script>
</body>
</html>
styles.css/* Basic reset and styling */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
h1 {
text-align: center;
color: #333;
}
/* Gallery grid */
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
padding: 20px;
}
.item {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
overflow: hidden;
cursor: pointer; /* Indicates clickable */
transition: transform 0.3s ease;
}
.item:hover {
transform: scale(1.05); /* Slight zoom on hover for better UX */
}
.item img {
width: 100%;
height: auto;
display: block;
}
.item p {
padding: 10px;
text-align: center;
font-size: 14px;
color: #666;
}
/* Lightbox styles */
.lightbox {
display: none; /* Hidden by default */
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
overflow: auto;
}
.lightbox-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}
#caption {
text-align: center;
padding: 10px 0;
color: white;
font-size: 18px;
}
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: #bbb;
}
script.js// JavaScript for lightbox functionality
document.addEventListener('DOMContentLoaded', function() {
const galleryItems = document.querySelectorAll('.item');
const lightbox = document.getElementById('lightbox');
const lightboxImg = document.getElementById('lightbox-img');
const captionText = document.getElementById('caption');
const closeBtn = document.querySelector('.close');
// Add click event to each gallery item
galleryItems.forEach(item => {
item.addEventListener('click', function() {
const imgSrc = this.getAttribute('data-src'); // Larger image source
const caption = this.querySelector('p').innerText; // Get caption text
// Set the lightbox content
lightboxImg.src = imgSrc;
captionText.innerText = caption;
// Show the lightbox
lightbox.style.display = 'block';
});
});
// Close lightbox when close button is clicked
closeBtn.addEventListener('click', function() {
lightbox.style.display = 'none';
});
// Close lightbox when clicking outside the image
lightbox.addEventListener('click', function(e) {
if (e.target === lightbox) {
lightbox.style.display = 'none';
}
});
});
index.html, styles.css, and script.js) in the same folder.index.html in a web browser (double-click it or use a local server if you're developing).index.html, copy a <div class="item"> element and change the data-src and img src attributes to point to different images. Update the alt text and paragraph for better descriptions.https://via.placeholder.com/600x400?text=BLT+Sandwich) with actual image URLs. You can find free sandwich images on sites like Unsplash or Pexels.If this isn't what you had in mind (e.g., if "sandwich gallery" means something else, like a data visualization or a different type of app), let me know more details, and I can refine it! 🍔🥪 Enjoy your sandwich gallery! 😊