Skip to content

Instantly share code, notes, and snippets.

@cypnk
Created January 6, 2018 16:59
Show Gist options
  • Save cypnk/be7bf41b1a2e90758fbab13ce7078f3a to your computer and use it in GitHub Desktop.
Save cypnk/be7bf41b1a2e90758fbab13ce7078f3a to your computer and use it in GitHub Desktop.
Pure CSS checkbox confirmation (for deletions etc...)
<!DOCTYPE html>
<html>
<head>
<title>Delete confirmation</title>
<style>
body { font: 400 1em sans-serif; background: #f9f9ff; color: #444; }
label {
cursor: pointer;
}
/* Second confirmation container is hidden initially */
input[rel='conf'] ~ [rel='conf'] {
display: none;
}
/* Second container revealed if the first checkbox is checked */
input[rel='conf']:checked ~ [rel='conf'] {
display: inline-block;
}
</style>
</head>
<body>
<form method="post" action="/">
<p>
<!-- Primary checkbox -->
<input type="checkbox" name="del" id="del" value="1" rel="conf" />
<label for="del">Delete this post</label>
<!-- Secondary confirmation package -->
<span rel="conf"> |
Are you sure?
<label>
<strong>This cannot be undone</strong>
<!-- Secondary checkbox -->
<input type="checkbox" name="delconf" value="1" />
</label>
</span>
</p>
<p><input type="submit" value="Post" /></p>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment