Skip to content

Commit 275b295

Browse files
committed
fix: 修正複製按鈕滾動問題並調整按鈕位置
- 複製按鈕改用 position: sticky 避免滾動時移位 - 統一關閉按鈕和複製按鈕的邊距設計 - 調整程式碼區塊內距以配合按鈕位置 - 移除 hover 才顯示的設計,讓按鈕一直可見
1 parent aa362b8 commit 275b295

3 files changed

Lines changed: 14 additions & 20 deletions

File tree

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<meta http-equiv="Expires" content="0">
99
<meta name="theme-color" content="#000000">
1010
<title>GitHub Copilot 教學專案</title>
11-
<link rel="stylesheet" href="style.css?v=20250603003">
11+
<link rel="stylesheet" href="style.css?v=20250603005">
1212
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
1313
<script src="https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"></script>
1414
</head>
@@ -352,6 +352,6 @@ <h3 style="font-size: 1.25rem; font-weight: 600; color: #1d1d1f; margin-bottom:
352352
</div>
353353
</div>
354354

355-
<script src="script.js?v=20250603003"></script>
355+
<script src="script.js?v=20250603005"></script>
356356
</body>
357357
</html>

script.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function addCopyButtons() {
195195

196196
// 創建按鈕容器
197197
const buttonContainer = document.createElement('div');
198-
buttonContainer.style.cssText = 'position: absolute; top: 5px; right: 5px; display: flex; gap: 5px; align-items: center;';
198+
buttonContainer.style.cssText = 'position: sticky; top: 10px; float: right; margin-right: -5px; margin-top: -35px; display: flex; gap: 5px; align-items: center; z-index: 10;';
199199

200200
// 如果有語言標示,添加語言標籤
201201
if (language) {
@@ -265,8 +265,8 @@ function addCopyButtons() {
265265
// 添加按鈕到容器
266266
buttonContainer.appendChild(button);
267267

268-
// 添加容器到程式碼區塊
269-
block.appendChild(buttonContainer);
268+
// 將容器插入到程式碼區塊的開頭
269+
block.insertBefore(buttonContainer, block.firstChild);
270270
});
271271
}
272272

style.css

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,12 @@ body {
661661

662662
.markdown-close {
663663
position: sticky;
664-
top: 10px;
664+
top: 15px;
665665
float: right;
666666
margin-left: 20px;
667667
margin-bottom: 20px;
668-
margin-top: -10px;
669-
margin-right: -10px;
668+
margin-top: -20px;
669+
margin-right: -20px;
670670
width: 36px;
671671
height: 36px;
672672
cursor: pointer;
@@ -720,9 +720,9 @@ body {
720720

721721
@media (max-width: 768px) {
722722
.markdown-close {
723-
top: 5px;
724-
margin-right: -5px;
725-
margin-top: -5px;
723+
top: 10px;
724+
margin-right: -10px;
725+
margin-top: -10px;
726726
width: 32px;
727727
height: 32px;
728728
border-radius: 16px;
@@ -774,7 +774,8 @@ body {
774774
background: rgba(142, 142, 147, 0.08);
775775
border: none;
776776
border-radius: 12px;
777-
padding: 20px;
777+
padding: 15px;
778+
padding-top: 45px;
778779
overflow-x: auto;
779780
margin: 20px 0;
780781
position: relative;
@@ -803,17 +804,10 @@ body {
803804

804805
.markdown-content pre .copy-button,
805806
.markdown-content pre .lang-label {
806-
opacity: 0;
807+
opacity: 1;
807808
transition: opacity 0.3s;
808-
position: absolute;
809-
top: 20px;
810-
right: 20px;
811809
}
812810

813-
.markdown-content pre:hover .copy-button,
814-
.markdown-content pre:hover .lang-label {
815-
opacity: 1;
816-
}
817811

818812
.copy-button:hover {
819813
background: #0077ed;

0 commit comments

Comments
 (0)