JSFiddle - React, Tailwind, and code Playground
by wuchengyang
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>貓咪熱量計算機</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
background-color: #f9f9f9;
}
.calculator-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
background: #ffffff;
padding: 20px;
border: 2px solid #ddd;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
input {
width: 150px;
padding: 5px;
font-size: 16px;
text-align: center;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.result {
font-size: 18px;
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<div class="calculator-container">
<input type="number" id="weight" placeholder="貓咪體重(kg)">
<button onclick="calculateCalories()">計算熱量</button>
<div class="result" id="result">每日熱量:0 kcal</div>
</div>
<script>
function calculateCalories() {
const weight = parseFloat(document.getElementById('weight').value);
if (isNaN(weight) || weight <= 0) {
document.getElementById('result').innerText = "請輸入有效的體重";
return;
...