Consider a Child
component with scoped styles, which internally uses foo
class name:
<!-- Child -->
<template>
<div class="foo">
This is a child
</div>
</template>
<style scoped>
.foo {
color: blue;
}
</style>
and another Parent
component with scoped styles, which internally uses foo
class name as well, and also provides a slot:
<!-- Parent -->
<template>
<div class="foo">
<div>This is a parent</div>
<slot></slot>
</div>
</template>
<style scoped>
.foo {
color: red;
margin-bottom: 10px;
}
</style>
Nest Child
component into Parent
component as a slot:
<!-- App -->
<template>
<div>
<Parent>
<Child />
</Parent>
</div>
</template>
<script>
import Parent from "./components/Parent";
import Child from "./components/Child";
export default {
components: {
Parent,
Child
}
};
</script>
Actual result
styles of the foo
class from the Parent
are also applied to an element with a foo
class in the Child
. Here is a screenshot of the actual DOM:
Expected result
I would expect that styles for a Child
will be isolated from any parent. I wonder if it is by design or can be fixed without renaming the classes, because it will break the whole idea of isolation.
Here is a CodeSandbox to play around with the sources.