5

I have created a headless application with vue and now I need to load a css file exclusively for a specific component.
In the code below I have inserted the css file, but unfortunately it is displayed globally throughout the application.

<script>
export default {
name: "FriendComponent",
...
}
</script>

<style>
@import 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css';
</style>

1 Answer 1

2

To apply any CSS file or code to a specific component, you need to add scoped in your style tag of the component.

Have a look at this:

<style scoped>
@import 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css';
</style>

This will apply CSS to this specific component.

Sign up to request clarification or add additional context in comments.

2 Comments

I have also tried inserting scoped, but the css file is read globally.
@user17368086 are you sure you haven't defined the same CSS file else where?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.