I have the following form component:
<template> <div> <form> <input placeholder="Recipe Name"> <textarea placeholder="Recipe Description..." rows="10"></textarea> </form> </div> </template> <script> export default { name: 'AddRecipeForm' } </script> <style scoped> form { display: flex; flex-direction: column; } </style>
The <style>
uses the scoped
attribute.
When applied, the CSS does not get loaded in. When scoped
is removed, it does get applied.
However I want to keep it local to the component.
Why is the CSS not getting applied when the scoped
attribute is present?
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.
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.
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.
The scoped attribute is a boolean attribute. When present, it specifies that the styles only apply to this element's parent element and that element's child elements (not the entire document). Note: The scoped attribute is deprecated and will be removed.
It appears this was solved by doing a full-reload of the page. Hot reload should take care of scoped css.
However for future viewers, This is commonly asked when scoped CSS isnt being applied to a child component. This can be solved by using deep selectors. (e.g: Using a .selector >>> .desired-selector {}
)
EDIT: Since this is still getting activity, I'll bring my comment into the answer. ::v-deep
also works depending on what preprocessor you're using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With