Styling limitations encountered when using lang="scss" with scoped css

My current project involves using Quasar and I am attempting to style the first column of q-table:

<style lang="scss" scoped>
td:first-child {
  background-color: #747480 !important;
}
</style>

Unfortunately, this code does not seem to have any effect even after trying various methods like reloading, hot reloading, or restarting the server.

Strangely enough, when I remove the "scoped" attribute, it works perfectly. I'm confused as to why this is happening. Can anyone suggest a solution for this issue?

EDIT: I have created a working demo:

Codesandbox

If you simply remove the "scoped" attribute from the style, you will see the color change take effect.

Answer №1

Latest Update: The piercing selector in Vue 3 is now :deep(). For example:

.qtable :deep(tbody td) {
  white-space: normal;
}

This will result in output like this:

.qtable[data-v-f3f3eg9] tbody td {
  white-space: normal;
}

Initial Response:

Caution when using >>> with lang="scss"!

While >>> works as expected without specifying a lang (or setting it to css), the same cannot be said for lang="scss".

The only effective piercing selectors for lang="scss" (in Vue 2.x — v2.6.11) are /deep/ and ::v-deep.
I have tested with both node-sass and dart-sass packages, but the behavior remains consistent. It seems to be an issue at either the Vue package or Sass package level.

Interestingly, >>> is replaced by > > > in scss, rendering the code block ineffective. The desired behavior should be to remove >>> and not apply scoping attribute to subsequent parts of the selector (as done with other piercing selectors).

Note that this used to work previously, and I am unsure why or when it ceased to function. Personally, I have always favored using ::v-deep without any specific rationale.

To solve this issue, simply encapsulate everything within ::v-deep {}:

<style lang="scss" scoped>
  ::v-deep {
    td:first-child {
      background-color: #747480; /* no need for !important */
    }
    .q-table tbody td {
      white-space: normal;
    }
  }
</style>

By doing so, the styles will be applied correctly.

Answer №2

Utilize the deep selector within scoped styles

To implement this, include an "id" attribute in your q-table component

<q-table
    title="Treats"
    :data="data"
    :columns="columns"
    row-key="name"
    dark
    color="amber"
    id="my-custom-table"
        />

Next, adjust your scoped style to resemble the following example

<style scoped>
  #my-custom-table >>> td:first-child {
    background-color: #1313eb !important;
  }

 .q-table tbody td {
    white-space: normal;
 }
</style>

Answer №3

When using

<style scoped lang="scss">
, such as in Vue.js, remember that the deep selector /deep/ is necessary instead of >>> between parent and child tags to apply CSS parameters to all children elements:

// This will not apply to all children and will not work:
.my-table .cell {
  word-break: keep-all;
}

// Apply it to all children elements:
.my-table /deep/ .cell {
  word-break: keep-all;
}

/deep/ or ::v-deep serves as a substitution for >>> in the Sass scoped pre-processor.

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

JavaScript providing inaccurate height measurement for an element

Upon loading the page, I am trying to store the height of an element. To achieve this, I have utilized the jQuery "ready" function to establish a callback: var h_top; var h_what; var h_nav; $(".people").ready(function() { h_top = $(".to ...

What is the best way to transmit two distinct sets of data from a child component to the v-model of a parent component?

Currently, I am working on a project using vuejs 2 and typescript. In this project, I need to pass two different sets of data - data and attachments - within the parent component. I am utilizing vue-property-decorator for this purpose. However, I am facing ...

stacking order of floated and positioned elements

After researching on MDN and reading through this insightful blog post, it is suggested that in the absence of a z-index, positioned elements are supposed to stack above float elements when they overlap. However, upon closer examination, the example prov ...

The pre-loader is hidden behind the block content and navigation bar

I've encountered an issue with my preloader where it's loading in front of the <body> element but not in front of the site's <navbar> or the {% block content %}. The CSS snippet to increase the z-index of the preloader is as foll ...

What is the best way to ensure that all elements inside a Grid item extend to the bottom, except for the text?

I currently have four columns within a Grid container, each structured as follows: <Grid item> <Typography>Big Title 1</Typography> <Card className={classes.stretchMe}> <CardContent> ...

In Bootstrap 4, the positioning of :after is different compared to Bootstrap 3

Our bootstrap nav-tabs have a unique default look with an 'indicator' icon below the selected tab. This is achieved by styling the active anchor element as follows: https://i.sstatic.net/UQos5.png However, when migrating to bootstrap 4, we noti ...

What is the reason for the continual appearance of the *ngIf validation message?

Currently, I am working with Angular and HTML. I have implemented pattern validation for the first name field, which should not accept only numbers. <fieldset class="six"> <input id="firstName" ng-pattern="^[a-zA-Z]+$" type="text" ...

Encountering issues with loading styles in Vue single file components

While working on my project at this link, I encountered an issue with displaying a styled modal. Despite trying to import the styles using: <style scoped> @import "../styles/modal-style.css"; </style> and even directly pasting the co ...

Why does the width of my image appear differently on an iPhone compared to other devices?

I recently encountered an issue with the responsiveness of an image on my website. While it displayed correctly on Android and desktop devices, the image appeared distorted on iPhones as if the CSS width attribute was not applied properly. This problem spe ...

The VUE project I'm working on seems to be having compatibility issues with the Bootstrap modal in V

I added bootstrap using npm and inserted the code from bootstrap into my project, but it's not functioning correctly. I've spent an hour trying to troubleshoot, but still no luck. Here is the code snippet: <template> <div> <! ...

Accessing .js and .css libraries from shared views in ASP.NET Core can be restricted

I am currently developing a simple application on ASP.NET core 3.1, and I'm facing a basic problem that I can't seem to solve. The menu of the application is located in a Shared view called _Layout.cshtml. I load .js and .css libraries in this v ...

I am facing an issue with Recharts not occupying the full width in my Nextjs/Reactjs project. Despite setting it to 100% width, it does not behave as

I am currently working with Recharts in combination with Next.js and Tailwindcss. I decided to create my own barchart by copying a code snippet from Recharts, but encountered an issue where changing the height to aspect worked fine, however setting the wid ...

Set up a programmatic way to manage errors in Vue using Mocha

In almost all of my unit tests in Mocha, I consistently include the following code snippet at the beginning: it('should do something', (done) => { Vue.config.errorHandler = done; // perform some asynchronous action }); By default, Vue h ...

Using vue-resource to intercept an ajax error and catching the "Uncaught (in promise)" exception

I am utilizing vue-resource to retrieve data from the server. In order to access the correct data, a user must possess a JWT token. If the token is invalid or has expired, a status code of 401 will be returned. Similarly, if a user attempts to reach a forb ...

What is the best way to display a loading screen while simultaneously making calls to multiple APIs?

I'm currently working with Angular 8 to develop an application that retrieves responses from various APIs for users. The application is designed to simultaneously call multiple APIs and I require a loading indicator that stops once each API delivers a ...

A guide on connecting a source property in a v-for loop

After following this tutorial, I attempted to iterate through the 'items' array and display the 'item.message' property dynamically. However, during runtime, I encountered the error message shown below: Elements in iteration expect to h ...

I am experiencing difficulties with getting Google Analytics to function properly within my VuePress project

Recently, I started a new vuepress project I am attempting to implement Google Analytics to track its progress. However, there seems to be an issue connecting my project with Google Analytics I followed the Documentation Guide ( ) to include yarn add - ...

The functionality of the Bootstrap dropdown list button is not functioning properly on mobile devices

Currently, I am in the process of developing a website and testing its mobile view on my iPhone. The website is still using bootstrap 3, but I have encountered some issues. When I tap on the navigation button on my iPhone, nothing happens - no dropdown lis ...

Unable to show the company logo in the navigation bar

Working on a pizza site and encountering an issue - trying to add the logo of the place to the navbar (which also links to the main page) but it's not displaying. Using Twitter Bootstrap for this project. Here is the code snippet: /*#557c3e green*/ ...

Can a Vue.js project import the bootstrap.min.js file?

I have been working on a project in Vue.js where Bootstrap is already integrated. The project consists of HTML and CSS which I am converting into a Vue.js application while utilizing Bootstrap classes. However, I have encountered an issue with the dropdown ...