165 lines
4.9 KiB
HTML
165 lines
4.9 KiB
HTML
Voici un exemple de composant captcha complet (HTML/CSS/JS) avec un design moderne, responsive et animations CSS :
|
|
|
|
**captcha.html**
|
|
```html
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Captcha</title>
|
|
<link rel="stylesheet" href="styles.css">
|
|
</head>
|
|
<body class="bg-gray-100">
|
|
<div class="max-w-md mx-auto p-6 mt-12">
|
|
<h2 class="text-lg font-bold text-gray-800">Captcha</h2>
|
|
<div class="captcha-container relative mt-6">
|
|
<div class="captcha-image">
|
|
<img src="captcha.png" alt="Captcha" class="w-full h-full object-cover">
|
|
</div>
|
|
<div class="captcha-grid relative">
|
|
<div class="captcha-box grid grid-cols-4 gap-4 h-full w-full">
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-1" readonly>
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-2" readonly>
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-3" readonly>
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-4" readonly>
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-5" readonly>
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-6" readonly>
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-7" readonly>
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-8" readonly>
|
|
<input type="text" class="w-full h-full p-2 border border-gray-400 rounded-lg" id="captcha-input-9" readonly>
|
|
</div>
|
|
</div>
|
|
<button class="relative btn mt-6" id="btn-submit">
|
|
<span class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2">
|
|
<svg class="w-6 h-6 fill-current text-gray-800" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-8zm-2-3a3 3 0 0 0-3 3v2h3a1 1 0 0 1 1 1v3h1a1 1 0 0 1 1-1v-4a1 1 0 0 1 1-1h1v-2z"></path>
|
|
<circle cx="12" cy="7" r="3"></circle>
|
|
</svg>
|
|
</span>
|
|
Soumettre
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<script src="script.js"></script>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
**styles.css**
|
|
```css
|
|
:root {
|
|
--gray-100: #f7f7f7;
|
|
--gray-800: #202020;
|
|
}
|
|
|
|
.bg-gray-100 {
|
|
background-color: var(--gray-100);
|
|
}
|
|
|
|
.max-w-md {
|
|
max-width: 400px;
|
|
}
|
|
|
|
.mx-auto {
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
}
|
|
|
|
.p-6 {
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.mt-12 {
|
|
margin-top: 3rem;
|
|
}
|
|
|
|
.text-lg {
|
|
font-size: 1.125rem;
|
|
}
|
|
|
|
.text-gray-800 {
|
|
color: var(--gray-800);
|
|
}
|
|
|
|
.captcha-container {
|
|
background-color: var(--gray-100);
|
|
padding: 1.5rem;
|
|
border-radius: 0.375rem;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
|
|
}
|
|
|
|
.captcha-image {
|
|
background-color: #fff;
|
|
padding: 1.5rem;
|
|
border-radius: 0.375rem 0.375rem 0 0;
|
|
}
|
|
|
|
.captcha-image img {
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
}
|
|
|
|
.captcha-grid {
|
|
position: relative;
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.captcha-box {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, 1fr);
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.captcha-box input {
|
|
background-color: var(--gray-100);
|
|
border: none;
|
|
padding: 0.5rem;
|
|
}
|
|
|
|
.btn {
|
|
background-color: var(--gray-100);
|
|
border: 1px solid var(--gray-800);
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 0.375rem;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.btn svg {
|
|
fill: var(--gray-800);
|
|
}
|
|
|
|
.btn:hover {
|
|
background-color: var(--gray-800);
|
|
color: #fff;
|
|
}
|
|
|
|
.btn:hover svg {
|
|
fill: #fff;
|
|
}
|
|
```
|
|
|
|
**script.js**
|
|
```javascript
|
|
// Créer un nouveau captch
|
|
function createCaptcha(image, box) {
|
|
const ctx = image.getContext('2d');
|
|
ctx.fillStyle = '#fff';
|
|
ctx.fillRect(0, 0, image.width, image.height);
|
|
const fontSize = 24;
|
|
const font = 'Arial';
|
|
const text = `C'est un ejemplo de captch`;
|
|
const textMetrics = ctx.measureText(text);
|
|
const x = (image.width - textMetrics.width) / 2;
|
|
const y = (image.height + font) / 2 + fontSize;
|
|
ctx.font = `${fontSize}px ${font}`;
|
|
ctx.fillStyle = '#000';
|
|
ctx.textAlign = 'center';
|
|
ctx.textBaseline = 'top';
|
|
ctx.fillText(text, x, y);
|
|
const grid = box.children;
|
|
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
for (let i = 0; i < grid.length; i++) {
|
|
const input = grid[i];
|
|
input.value = letters[Math.floor(Math.random() * letters.length |