样式冲突问题模板
This commit is contained in:
94
src/App.vue
94
src/App.vue
@@ -8,6 +8,8 @@
|
||||
<router-link to="/home">首页</router-link>
|
||||
<router-link to="/child-app">Vue2 子应用</router-link>
|
||||
<router-link to="/vue3-app">Vue3 子应用</router-link>
|
||||
<router-link to="/mock-app">💥主vs子</router-link>
|
||||
<router-link to="/mock-app-2">🔵子vs子</router-link>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="app-main">
|
||||
@@ -21,7 +23,13 @@
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* 全局样式重置 */
|
||||
/* ============================================
|
||||
全局样式重置(主应用)
|
||||
注意:以下使用了 h2 / button / p / table / code
|
||||
等通用选择器。在微前端场景中,这些选择器会:
|
||||
1. 影响主应用自身的元素 ✅ (预期行为)
|
||||
2. 泄漏到 iframe: false 的子应用中 ⚠️ (样式冲突)
|
||||
============================================ */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
@@ -40,6 +48,90 @@ html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* ---------- 冲突演示:主应用全局样式 ---------- */
|
||||
/* 这些通用选择器如果被子应用的同名选择器覆盖,就会发生冲突 */
|
||||
|
||||
/* 冲突点 ①:h2 — 主应用想要紫色渐变标题 */
|
||||
h2 {
|
||||
font-family: 'Microsoft YaHei', sans-serif !important;
|
||||
font-size: 20px !important;
|
||||
color: #667eea !important;
|
||||
border-bottom: 2px solid #667eea !important;
|
||||
padding-bottom: 8px !important;
|
||||
margin: 12px 0 !important;
|
||||
text-transform: none !important;
|
||||
border-left: none !important;
|
||||
}
|
||||
|
||||
|
||||
/* 冲突点 ②:button — 主应用想要紫色直角按钮 */
|
||||
button {
|
||||
background: #667eea !important;
|
||||
color: #fff !important;
|
||||
border: none !important;
|
||||
border-radius: 4px !important;
|
||||
padding: 6px 16px !important;
|
||||
font-size: 13px !important;
|
||||
font-weight: 500 !important;
|
||||
cursor: pointer !important;
|
||||
letter-spacing: 0 !important;
|
||||
}
|
||||
button:hover {
|
||||
background: #5a6fd6 !important;
|
||||
transform: none !important;
|
||||
}
|
||||
|
||||
/* 冲突点 ③:p 段落 — 主应用想要紧凑排版 */
|
||||
p {
|
||||
font-size: 14px !important;
|
||||
line-height: 1.6 !important;
|
||||
color: #444 !important;
|
||||
margin-bottom: 8px !important;
|
||||
}
|
||||
|
||||
/* 冲突点 ④:table — 主应用想要紫色无边框表格 */
|
||||
table {
|
||||
border-collapse: collapse !important;
|
||||
width: 100% !important;
|
||||
border: none !important;
|
||||
}
|
||||
th {
|
||||
background: #667eea !important;
|
||||
color: white !important;
|
||||
padding: 8px !important;
|
||||
text-align: left !important;
|
||||
font-size: 13px !important;
|
||||
}
|
||||
td {
|
||||
padding: 6px 8px !important;
|
||||
border-bottom: 1px solid #e0e0e0 !important;
|
||||
font-size: 13px !important;
|
||||
}
|
||||
|
||||
/* 冲突点 ⑤:code 标签 — 主应用想要紫色代码块 */
|
||||
code {
|
||||
background: #e8e0f0 !important;
|
||||
color: #5e35b1 !important;
|
||||
border: 1px solid #b39ddb !important;
|
||||
padding: 2px 6px !important;
|
||||
border-radius: 3px !important;
|
||||
font-size: 13px !important;
|
||||
}
|
||||
|
||||
/* 主应用布局 */
|
||||
.main-style-source {
|
||||
display: inline-block;
|
||||
padding: 2px 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: bold;
|
||||
margin-left: 8px;
|
||||
}
|
||||
.label-main {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
#main-app {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
Reference in New Issue
Block a user