How to modify the child widget style of the parent widget in vue.

Source: Internet
Author: User

How to modify the child widget style of the parent widget in vue.

During Development Using vue, we sometimes reference external components, including the UI components (ElementUI and iview ).

When the <style> label has the scoped attribute, its CSS only applies to the elements in the current component.

However, after scoped is added to the parent component, the style of the parent component does not penetrate into the Child component. Therefore, writing the style of the Child component in the parent component is ineffective.

1. Remove scoped

After scoped is removed from the <style> of the parent component, the style of the Child component can be written in the parent component, but you will worry that the global style will be contaminated.

[Because we know that the correct position for using the global style is to use a global app.css]

2. Mix local and global styles

You can use a style with a scope and no scope in a component at the same time:

<Style>/* Global style */</style> <style scoped>/* local style */</style>

Write the style of the Child widget to the global style above.

3. Use the depth Selector

If you want a selector in the scoped style to be "more effective", such as affecting sub-components, you can use the >>> OPERATOR:

<style scoped>.a >>> .b { /* ... */}</style>

Some pre-processors such as SASS cannot be correctly parsed >>>. In this case, you can replace it with the/deep/operator -- this is an alias of>, and it works normally.

OK, the main content is the above.

Additional supplements:

1. DOM content created through v-html is not affected by style in scope, but you can still set styles for them through the depth selector.

2. CSS scope cannot replace class

3. Use descendant selector in recursive Components

In the above vue, the method for modifying the child component style of the parent component is all the content that I have shared with you. I hope to give you a reference and support for the customer's house.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.