Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scoped CSS not being applied within the component

Tags:

css

vue.js

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?

like image 628
alanbuchanan Avatar asked Dec 25 '16 13:12

alanbuchanan


People also ask

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.

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.

What does scoped mean CSS?

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.


1 Answers

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.

like image 96
Brandon Deo Avatar answered Sep 29 '22 07:09

Brandon Deo