Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do scoped external css in vue.js?

Tags:

css

vuejs2

I am new to vue.js and saw this video

https://www.youtube.com/watch?v=LsoLfELhG74

Which says you can do

<style scoped>
</style>

to scope the style, but this is if I embed it into the html page. What if I link to a .css file. How could you still scope the css?

Thanks

like image 422
omega Avatar asked Jun 19 '17 01:06

omega


People also ask

What is scoped CSS in Vue?

Scoped CSS # With scoped , the parent component's styles will not leak into child components. However, a child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS. This is by design so that the parent can style the child root element for layout purposes.

How do I apply for CSS at Vue?

Adding CSS classes in Vue We should apply the button CSS classes to the <button> in our ToDoForm component. Since Vue templates are valid HTML, this is done in the same way to how you might do it in plain HTML — by adding a class="" attribute to the element.

How do I add global CSS to Vue?

To add global CSS in Vue. js, we can import our global CSS file in main. js . import "./assets/css/main.

Can I use scoped CSS?

Allows CSS rules to be scoped to part of the document, based on the position of the style element. The attribute has been removed from the current specification.


1 Answers

You can add a src attribute to the style tag like this:

<style scoped src="./test.css">
</style>
like image 180
Mark Avatar answered Sep 23 '22 03:09

Mark