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

Excessive content spilling over the div container

Hello everyone I've been trying to set up a div that includes an image, a title, and some text. I want the image to be aligned on the left side, with the title and text following on the right. However, I'm having an issue where the text is overf ...

What are the best ways to change the styling of jquery ui widgets?

Currently utilizing jQuery UI, I have encountered an issue with the font size within a dialog. When utilizing the standard settings, the font size appears to be excessively large. To address this, I used the element inspector to identify the class name o ...

Avoiding leaps through the use of dynamic pictures?

Currently, I am implementing the picture element along with srcset to download the same image but in varying resolutions depending on the screen size of the device. The image has a style of max-width: 100%, causing it to shift the content below when downl ...

Utilize VueJS to upload and visualize a file input on your website

I am currently working with TypeScript and Haml in conjunction with vue.js. My goal is to enable users to upload and view a file seamlessly using the vue.js framework. I have successfully managed to upload an image, however, I am facing an issue where the ...

Tips for extracting a computed property value and storing it in an array variable

In my project, I have implemented a computed property function named Total. This function is responsible for calculating the total value of name + value pairs from an array called prices. It is utilized in a quotation form where the running total is displa ...

Combining 1 pixel borders to create a bolder border effect

How can I prevent the border from becoming 2 pixels when I have overlapping (touching) divs? I thought about putting borders on only 2 sides, but then one edge of the div would be without a border. By the way, I am utilizing jQuery Masonry. ...

SVG padding will only take effect if two or more sides are specified

What is the reason behind an SVG requiring at least 2 areas to be padded for padding to apply? For instance, applying padding-top: 50px to an svg element will have no effect. However, adding padding-top: 50px; padding-left: 1px will result in the padding ...

Error: The function you are trying to reference is undefined

I am facing an issue where I am receiving a "ReferenceError: doNotification is not defined" message when attempting to display a pop-up notification upon successful promise. Oddly enough, triggering doNotification on button click within my HTML works wit ...

Error: Unable to access 'isCE' property of null - Custom Component Library

Struggling to create a custom component library for Vue 3 using ViteJS and NPM. Here is a breakdown of my setup, can someone guide me in the right direction as I have hit a roadblock for the past couple of days. Here's how my files are structured: d ...

conceal menu upon click (gradually disappear)

This is a basic HTML/CSS menu. Currently, it is functioning properly for page redirection (href). However, I would like it to hide after being clicked on. I plan to call a function that will initiate an AJAX request upon clicking. Here is the code on JS ...

Having trouble getting Sass extending to work in a basic scenario?

Here we have a simple example of Sass code, an Angular 2 component that accesses the Sass code, and the rendered HTML. However, there seems to be an issue with the blueBig span element in the last part. As someone new to Sass, I am not sure why this basic ...

Using jQuery to dynamically change the CSS color based on the background-color of a checkbox label

When a checkbox is selected, the function below runs to change the text color to white or black based on the darkness of the background color. However, the third checkbox should trigger this change to white but currently does not. function isDark(color) { ...

If you press Ctrl + F, the browser will disable the form search function

How can I prevent the form find browser functionality when pressing Ctrl+F, and instead focus on the element html? <div id='demo'> <form class="id5-text-find-form" id="id5-text-find-form"> <input class="search" placeho ...

Looking for help with aligning an icon to the right side of my text

I'm struggling with aligning the icon to the right of the quantity. When I use float:right, it places the icon at the far right of the cell instead of next to the text. Is there a way to get it to be on the right side of the text but directly adjacent ...

Internet Explorer 11 fails to interpret the attribute attr.xlink:href

I am a beginner in Angular 2 and I'm working on creating an icon component. The code I have below works perfectly in Chrome and Firefox, but unfortunately, it's not functioning in Internet Explorer 11. Here is what my component looks like: @Com ...

Trigger a 'change password' notification using Javascript

Issue: I am currently working on developing a web application that includes a password change functionality without the use of form submission. The process I have in mind is as follows: Show a Bootstrap modal pop-up User enters new password Upon clickin ...

Changing the CSS class of the Bootstrap datetime picker when selecting the year

Is there a way to change the CSS style of the Bootstrap datetime picker control so that when selecting years, the color changes from blue to red? I attempted to do this with the following code: .selectYear { background-color:red!important; } However ...

What is causing my css elements to appear larger compared to other instances?

As someone who is not a designer, I find myself doing a lot of cutting and pasting for my side hustles. I believe many others can relate to this experience. Currently, I am working on a personal project that involves using tailwindcss, appwrite, and svelte ...

Eliminate any vacant areas within a container and shift the container, along with its contents, on the webpage

I want to eliminate the empty space within the container while maintaining some spacing around the black box, and ensure responsiveness. Additionally, how can I shift the container with its content downwards and to the right of the webpage, while still ke ...

Choose tag using position in a sequence

I am working on updating the label text "E-mail" to say "User Name" in this HTML markup. The only tool I have access to for this task is jQuery. <div class="foo" style="border:1px solid #444"> <span class="field-with-fancyplaceholde ...