u
This commit is contained in:
1 parent
48dac36685
commit
d17b49cdd9
18 files changed
+532
-340
No files matched your search
@@ -1,115 +1,105 @@
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>按钮示例</title>
|
||||
<!-- 这里使用 Font Awesome CDN,你可以换成自己的图标库 -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
|
||||
<style>
|
||||
.btn {
|
||||
display: inline-flex; /* 内部水平排列 */
|
||||
align-items: center; /* 垂直居中 */
|
||||
justify-content: center; /* 水平居中 */
|
||||
gap: 4px; /* 图标和文字间距 */
|
||||
padding: 8px 16px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
background-color: #f4f5f5;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Popup with Arrow</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 50px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
/* 触发按钮 */
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
background-color: #dcdcdc;
|
||||
}
|
||||
/* Popup 基础样式 */
|
||||
.popup {
|
||||
position: absolute;
|
||||
padding: 10px 15px;
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
|
||||
display: none;
|
||||
z-index: 100;
|
||||
max-width: 200px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px; /* 控制图标大小 */
|
||||
}
|
||||
/* 箭头公共样式 */
|
||||
.popup::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 图标在左 -->
|
||||
<button class="btn">
|
||||
<i class="fas fa-check btn-icon"></i>
|
||||
<span class="btn-text">按钮文字</span>
|
||||
</button>
|
||||
/* 箭头方向 */
|
||||
.popup.top::after {
|
||||
bottom: -8px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
border-width: 8px 8px 0 8px;
|
||||
border-color: #333 transparent transparent transparent;
|
||||
}
|
||||
|
||||
<!-- 图标在右 -->
|
||||
<button class="btn">
|
||||
<span class="btn-text">按钮文字</span>
|
||||
<i class="fas fa-arrow-right btn-icon"></i>
|
||||
</button>
|
||||
</body>
|
||||
</html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>按钮示例</title>
|
||||
<!-- 这里使用 Font Awesome CDN,你可以换成自己的图标库 -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
|
||||
<style>
|
||||
.btn {
|
||||
display: inline-flex; /* 内部水平排列 */
|
||||
align-items: center; /* 垂直居中 */
|
||||
justify-content: center; /* 水平居中 */
|
||||
gap: 4px; /* 图标和文字间距 */
|
||||
padding: 8px 16px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
background-color: #f4f5f5;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
background-color: #dcdcdc;
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px; /* 控制图标大小 */
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 图标在左 -->
|
||||
<button class="btn">
|
||||
<i class="fas fa-check btn-icon"></i>
|
||||
<span class="btn-text">按钮文字</span>
|
||||
</button>
|
||||
|
||||
<!-- 图标在右 -->
|
||||
<button class="btn">
|
||||
<span class="btn-text">按钮文字</span>
|
||||
<i class="fas fa-arrow-right btn-icon"></i>
|
||||
</button>
|
||||
</body>
|
||||
.popup.bottom::after {
|
||||
top: -8px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
border-width: 0 8px 8px 8px;
|
||||
border-color: transparent transparent #333 transparent;
|
||||
}
|
||||
|
||||
.popup.left::after {
|
||||
top: 50%;
|
||||
right: -8px;
|
||||
transform: translateY(-50%);
|
||||
border-width: 8px 0 8px 8px;
|
||||
border-color: transparent transparent transparent #333;
|
||||
}
|
||||
|
||||
.popup.right::after {
|
||||
top: 50%;
|
||||
left: -8px;
|
||||
transform: translateY(-50%);
|
||||
border-width: 8px 8px 8px 0;
|
||||
border-color: transparent #333 transparent transparent;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<button class="btn" id="btn">Hover me</button>
|
||||
|
||||
<div class="popup top" id="popup">这是一个带箭头的 Popup!</div>
|
||||
|
||||
<script>
|
||||
const btn = document.getElementById('btn');
|
||||
const popup = document.getElementById('popup');
|
||||
|
||||
// 鼠标悬停显示
|
||||
btn.addEventListener('mouseenter', () => {
|
||||
const rect = btn.getBoundingClientRect();
|
||||
popup.style.display = 'block';
|
||||
// 设置 Popup 位置(示例:顶部)
|
||||
popup.style.left = rect.left + rect.width / 2 - popup.offsetWidth / 2 + 'px';
|
||||
popup.style.top = rect.top - popup.offsetHeight - 10 + 'px';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
popup.style.display = 'none';
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user