o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
Make a website with riddles using HTML + CSS (one file)
- User
Make a website with riddles using HTML + CSS (one file)
- Assistant
Make a website with riddles using HTML + CSS (one file)
Sure! Below is a complete HTML file that creates a simple and stylish riddle website using only HTML and CSS. This website displays a list of riddles, and users can click on each riddle to reveal the answer.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Riddle Zone</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f0f4f8;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
min-height: 100vh;
}
.container {
width: 90%;
max-width: 800px;
margin: 50px auto;
background: #fff;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
padding: 20px 30px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
.riddle {
border-bottom: 1px solid #ddd;
padding: 15px 0;
}
.riddle:last-child {
border-bottom: none;
}
.question {
font-size: 1.1em;
cursor: pointer;
position: relative;
padding-right: 25px;
}
.question::after {
content: '+';
position: absolute;
right: 0;
top: 0;
font-size: 1.2em;
transition: transform 0.3s;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]:checked + .question::after {
transform: rotate(45deg);
}
.answer {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
color: #555;
padding-left: 20px;
margin-top: 5px;
}
input[type="checkbox"]:checked ~ .answer {
max-height: 100px; /* Adjust based on content */
margin-top: 10px;
}
/* Responsive Design */
@media (max-width: 600px) {
.container {
padding: 15px 20px;
}
.question {
font-size: 1em;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome to Riddle Zone</h1>
<div class="riddle">
<input type="checkbox" id="riddle1">
<label class="question" for="riddle1">I speak without a mouth and hear without ears. I have nobody, but I come alive with the wind. What am I?</label>
<div class="answer">
<p><strong>Answer:</strong> An echo.</p>
</div>
</div>
<div class="riddle">
<input type="checkbox" id="riddle2">
<label class="question" for="riddle2">You measure my life in hours and I serve you by expiring. I’m quick when I’m thin and slow when I’m fat. The wind is my enemy.</label>
<div class="answer">
<p><strong>Answer:</strong> A candle.</p>
</div>
</div>
<div class="riddle">
<input type="checkbox" id="riddle3">
<label class="question" for="riddle3">I have cities, but no houses; forests, but no trees; and water, but no fish. What am I?</label>
<div class="answer">
<p><strong>Answer:</strong> A map.</p>
</div>
</div>
<div class="riddle">
<input type="checkbox" id="riddle4">
<label class="question" for="riddle4">What is seen in the middle of March and April that can’t be seen at the beginning or end of either month?</label>
<div class="answer">
<p><strong>Answer:</strong> The letter "R".</p>
</div>
</div>
<div class="riddle">
<input type="checkbox" id="riddle5">
<label class="question" for="riddle5">You see a boat filled with people. It has not sunk, but when you look again you don’t see a single person on the boat. Why?</label>
<div class="answer">
<p><strong>Answer:</strong> All the people were married.</p>
</div>
</div>
</div>
</body>
</html>
HTML Structure:
<div class="container"> serves as the main wrapper for the content, centering it on the page with some padding and a white background for contrast.<div class="riddle">.<input type="checkbox"> is hidden and used to toggle the visibility of the answer. Each checkbox has a unique id.<label class="question" for="riddleX"> is clickable and associated with the corresponding checkbox. Clicking the label checks/unchecks the checkbox, triggering the CSS to show or hide the answer.<div class="answer"> contains the answer to the riddle and is initially hidden.CSS Styling:
+) on the right. When the associated checkbox is checked, the plus rotates to form an 'X'.max-height. This creates an accordion-like effect without JavaScript..riddle divs and update the id, for attribute in the label, question text, and answer.<style> tags..html extension, for example, riddles.html.Feel free to customize and expand this template to suit your needs. Enjoy creating your riddle website!
Not yet included in a published release.