-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic_gates.html
115 lines (102 loc) · 2.96 KB
/
logic_gates.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>逻辑门模拟器 (纯CSS实现)</title>
<style>
.gate {
margin: 20px;
padding: 15px;
border: 2px solid #333;
border-radius: 5px;
display: inline-block;
}
.input {
margin: 5px;
}
.output {
margin-top: 10px;
font-weight: bold;
}
/* AND 门逻辑修正 */
.gate:has(#and-a:checked):has(#and-b:checked) .and-output::after {
content: "1";
}
.gate:has(#and-a:not(:checked)) .and-output::after,
.gate:has(#and-b:not(:checked)) .and-output::after {
content: "0";
}
/* OR 门逻辑修正 */
.gate:has(#or-a:checked) .or-output::after,
.gate:has(#or-b:checked) .or-output::after {
content: "1";
}
.gate:has(#or-a:not(:checked)):has(#or-b:not(:checked)) .or-output::after {
content: "0";
}
/* NOT 门逻辑修正 */
.gate:has(#not-a:checked) .not-output::after {
content: "0";
}
.gate:has(#not-a:not(:checked)) .not-output::after {
content: "1";
}
/* 基础输出样式 */
.output span::after {
display: inline;
content: "0";
}
.output span {
display: inline;
}
/* 复选框样式 */
input[type="checkbox"] {
display: none;
}
/* 标签样式 */
label {
cursor: pointer;
padding: 2px 5px;
border: 1px solid #333;
margin: 0 5px;
}
/* 选中状态的标签样式 */
input[type="checkbox"]:checked + label {
background-color: #333;
color: white;
}
</style>
</head>
<body>
<h1>逻辑门模拟器 (纯CSS实现)</h1>
<div class="gate">
<h2>AND 门</h2>
<div class="input">
输入 A: <input type="checkbox" id="and-a"><label for="and-a">[ ]</label>
输入 B: <input type="checkbox" id="and-b"><label for="and-b">[ ]</label>
</div>
<div class="output">
输出: <span class="and-output"></span>
</div>
</div>
<div class="gate">
<h2>OR 门</h2>
<div class="input">
输入 A: <input type="checkbox" id="or-a"><label for="or-a">[ ]</label>
输入 B: <input type="checkbox" id="or-b"><label for="or-b">[ ]</label>
</div>
<div class="output">
输出: <span class="or-output"></span>
</div>
</div>
<div class="gate">
<h2>NOT 门</h2>
<div class="input">
输入: <input type="checkbox" id="not-a"><label for="not-a">[ ]</label>
</div>
<div class="output">
输出: <span class="not-output"></span>
</div>
</div>
</body>
</html>