When Vue uses v-html bindings, the elements inside do not inherit the external CSS, the solution

Source: Internet
Author: User

Problem

You want to bind the HTML content generated by the parent text with Vue, but find that the CSS style doesn't work at all and the selector doesn't.

Code:

<class= "announcedetailimg"  v-html= "Detaillist.content"  ></div>

Set Style:

<style lang= "less" scoped>.announcedetailimg {    width:100%;} . announcedetailimg img {    width:100%!important;     Display:block;} . announcedetailimg P {    color:#333;     font-size:16px;}     </style>

After this, the discovery style does not work

Solution:

The scoped property causes the CSS to take effect only for the current component (implemented with the CSS3 property selector + generated random property), and the HTML binding renders the content as a subcomponent, and the subcomponents are not added to the corresponding attributes, so the CSS is not applied.

If you fix it, just remove the scoped attribute.

When Vue uses v-html bindings, the elements inside do not inherit the external CSS, the solution

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.