What is preventing the scoped styles from loading on a Nuxt page?

In my Nuxt site, I have two separate Freshsales forms as components (formA and formB). I've customized the default form styles with scoped styles within those form components. However, when I use these forms on a page, the scoped styles don't get loaded and applied.

If I remove the scoping, the styles get applied but the styles from formA also affect any page using the formB component (which is expected in a Nuxt/Vue app).

Why aren't my scoped styles working?

Below is a sample code:

//contactForm.vue //xxx refers to the unique id

<template>
  <div>
    <script
      src="https://facilio.freshsales.io/web_forms/xxxxxx/form.js"
      crossorigin="anonymous"
      id="xxxxx"
    ></script>
  </div>
</template>
<style scoped>

.fserv-form {
  border-radius: 10px;
  padding: 20px;
  position: relative;
  font-family: Arial, sans-serif;
}
.fserv-field:nth-child(3){
  width: 187px;
  padding-right: 5px;
  display: inline-block;
}
.fserv-field:nth-child(5){
   width: 140px;
   padding: 0;
  display: inline-block;
}
@media screen and (max-width: 360px) {
  .fserv-field:nth-child(3) {
    width: 135px;
  }
  .fserv-field:nth-child(5) {
    width: 110px;
  }
}
@media screen and (max-width: 986px) and (min-width: 525px){
   .fserv-field:nth-child(3),.fserv-field:nth-child(5) {
  width: 100%;
  padding: 0 30px;
  display: block;
   }
}
</style>

//register.vue

<template>
  <div>
    <script
      src="https://facilio.freshsales.io/web_forms/xxxxxx/form.js"
      crossorigin="anonymous"
      id="xxxxx"
    ></script>
  </div>
</template>
<style scoped>

.fserv-form {
  border-radius: 10px;
  padding: 20px;
  position: relative;
  font-family: Arial, sans-serif;
}
.fserv-field{
  padding: 40px !important;
}
.fserv-field:nth-child(3){
  width: 187px;
  padding-right: 5px;
  display: inline-block !important;
}
.fserv-field:nth-child(4){
   width: 140px;
   padding: 0;
  display: inline-block !important;
}
@media screen and (max-width: 360px) {
  .fserv-field:nth-child(3) {
    width: 135px;
  }
  .fserv-field:nth-child(4) {
    width: 110px;
  }
}
@media screen and (max-width: 986px) and (min-width: 525px){
   ...
};
</style>

I'm facing an issue where if I scope the styles, they are not applied at all. But if I remove the scoping, the contact form styles apply to both pages. Is there a proper way to handle this so that styles can be separately applied to each form without conflicts? Thank you!

Answer №1

To customize child components in Vue without conflicts, utilize the >>> operator provided by Vue. You can apply styles using the scoped attribute. For more information, refer to this Documentation link.

Your updated code should now look like this:

<template>
  <div>
    <script
      src="https://facilio.freshsales.io/web_forms/xxxxxx/form.js"
      crossorigin="anonymous"
      id="xxxxx"
    ></script>
  </div>
</template>
<style scoped>

>>> .fserv-form {
  border-radius: 10px;
  padding: 20px;
  position: relative;
  font-family: Arial, sans-serif;
}
>>> .fserv-field:nth-child(3){
  width: 187px;
  padding-right: 5px;
  display: inline-block;
}
>>> .fserv-field:nth-child(5){
   width: 140px;
   padding: 0;
  display: inline-block;
}
@media screen and (max-width: 360px) {
  >>> .fserv-field:nth-child(3) {
    width: 135px;
  }
  >>> .fserv-field:nth-child(5) {
    width: 110px;
  }
}
@media screen and (max-width: 986px) and (min-width: 525px){
   >>> .fserv-field:nth-child(3), .fserv-field:nth-child(5) {
       width: 100%;
       padding: 0 30px;
       display: block;
   }
}
</style>

Additionally, you can make further adjustments to your code like so:

<template>
    <div>
        <script
            src="https://facilio.freshsales.io/web_forms/xxxxxx/form.js"
            crossorigin="anonymous"
            id="xxxxx"
        ></script>
    </div>
</template>
<style scoped>

>>> .fserv-form {
    border-radius: 10px;
    padding: 20px;
    position: relative;
    font-family: Arial, sans-serif;
}
>>> .fserv-field{
    padding: 40px !important;
}
>>> .fserv-field:nth-child(3){
    width: 187px;
    padding-right: 5px;
    display: inline-block !important;
}
>>> .fserv-field:nth-child(4){
     width: 140px;
     padding: 0;
    display: inline-block !important;
}
@media screen and (max-width: 360px) {
    >>> .fserv-field:nth-child(3) {
        width: 135px;
    }
    >>> .fserv-field:nth-child(4) {
        width: 110px;
    }
}
@media screen and (max-width: 986px) and (min-width: 525px) {
    >>> .fserv-field:nth-child(3), .fserv-field:nth-child(4) {
        width: 100%;
        padding: 0 30px;
        display: block;
    }
}
</style>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can images be resized according to screen resolution without relying on javascript?

Looking to use a large banner image on my website with dimensions of 976X450. How can I make sure that the image stretches to fit higher resolution monitors without using multiple images for different resolutions? ...

What steps can be taken to eliminate the 1-pixel line between the background and gradient?

https://i.sstatic.net/nbtkK.png How can I remove the line that appears between the block and the gradient background when zooming in, especially noticeable in Safari (After zooming a couple times, Cmd +) For more details, please refer to this jsfiddle li ...

Looping CSS text animation with typing effect

I am struggling with a CSS code that types out text, but it only does so once and I need it to repeat infinitely. Despite adding animation-iteration-count: infinite;, it still doesn't work as intended. Another issue is that it slows down at the end. H ...

Enhance User Experience with the Tooltip Feature and Customized

Here is the jQuery code I am using to style my tooltips: $(function() { // select all input fields within #tooltips and attach tooltips to them $("#tooltips :input").tooltip({ // place tooltip on the right edge position: "cen ...

What could be preventing me from updating data using a Vuex module?

Hello, this is my custom component code: methods:{ ...mapActions(['updateUsers']), Update(userID){ let formData = new FormData(); formData.append('new_name',this.editUser.new_name); ...

Unable to adjust the top padding of the navbar to 0 pixels

Having recently started learning HTML and CSS, I am encountering an issue with the padding on my navbar. I am unable to get it to align with the top of the site as there is a persistent space between the navbar and the top. Below is my HTML code: <!do ...

What is the best way to eliminate the final border in a row that has been applied using the <

I have a table where the tr is styled with a border. I am looking to eliminate the border from the last td in the tr. Here is an example: <table> <thead> <tr> <th>a</th> <th>b</th> <th&g ...

Bootstrap - A collapsed navigation button that remains fixed without the rest of the navbar

I'm currently working on a responsive drag and drop game that utilizes Bootstrap and jQuery UI. Within the game, I have implemented a collapsible navbar at the top of the page. To optimize space for buttons at the bottom, I am looking to hide the nav ...

What is the process of setting up a subelement in a Vue array?

I am currently working on incorporating an array read feature using Vue.js: {{ this.locations[this.record.carton.LocationID - 1].Location }} Although the code functions properly during runtime, it throws an error upon initial loading: app.js:55125 [Vue wa ...

Tips for designing a webpage where a div element adjusts to fit the screen, regardless of the width of the content inside

Can CSS3 or a JavaScript library be used to create a webpage with a div that contains content wider than the screen, such as a large image or newsletter, and still fits it to the screen without scrolling or clipping any content? Below is an image demonst ...

Adjust the height of the outer div automatically

Currently, I am attempting to dynamically set the height of div#container so that it adjusts based on its relative positioning and the absolute positioning of inner divs. Essentially, I want the inner divs to be centered within the container. <div id=" ...

Bring fontawesome into the Laravel environment with MDBVue integration

I attempted to integrate fontawesome into my laravel mdbvue setup. Upon installing mdbvue using the command: npm install mdbvue fontawesome was automatically added to my package-lock.json and can be found in the node_modules folder under @fortawesome. ...

Swipe up to illuminate div when validation fails

My JSP page includes a form with a div that displays error messages when validation fails. The errors are generated server-side, displayed inside the div using struts property tag. However, the issue I'm facing is that the submit button is located fa ...

Ways to activate a hover effect on an external element

Hello everyone! This is my first time posting here and I've been struggling to find a solution with my limited knowledge. I could really use some help on this: Is there a way to trigger a hover effect on an element that is not related (no parent, ch ...

`Modifying CSS in Bootstrap 4 for a personalized website design`

I am currently building a Bootstrap website for my sister, but I am facing issues with changing the CSS. Most of the time, the changes do not seem to take effect. I created a new file called "style.css" to override the Bootstrap styles and placed it below ...

Tips for creating a visually appealing table within a vue.js component

I am attempting to customize the appearance of the table within this Vue component. As far as I understand, I should generate the CSS within the data function and then connect it to the appropriate element in the template. My goal is to implement the foll ...

Having trouble with Gulp JS and CSS minification where existing minified files cannot be replaced

I've hit a roadblock in trying to resolve my search and google issue. My current challenge involves Gulp and cssmin. I can't seem to pinpoint the cause of an error. My aim is to have both the original CSS files and their minified versions in the ...

What is the reason for `this` becoming undefined within the filter() function in VueJS?

Currently, I am in the process of designing a Date of Birth (DOB) Form. The interesting part is that I have incorporated VueJS into the form to enhance user experience. The unique feature of this form is that users are required to input their month of bir ...

The fullscreen API allows for the creation of a full-screen element containing internal elements, while also enabling the functionality

Is it possible to utilize the fullscreen API to make any element fullscreen, even if it contains multiple internal elements, while still maintaining the functionality of dropdowns and other custom elements that may be located in different areas of the page ...

Looping through images using JQuery

I'm struggling with an image animation and can't quite figure out how to make it work. <div id="img_loop"> <img src="img/img1.jpg" alt="image1" /> <img src="img/img2.jpg" alt="image2" class="hidden" /> <img src="im ...