Font modification is unsuccessful in Vue-Material

Here is a snippet from my App.vue file where I encountered an issue with changing the font in the md-tabs component, taken from . The CSS line:

background: #42A5F5;

works perfectly fine, but this one does not:

color: #E3F2FD;

App.vue:

<template>
      <div id="app">

        <md-tabs md-sync-route>
          <md-tab id="tab-home" md-label="Home" to="/"></md-tab>
          <md-tab id="tab-settings" md-label="Settings" to="/Settings"></md-tab>

        </md-tabs>

        <router-view></router-view>
      </div>
    </template>

    <script>
      export default {
        name: 'App'
      }
    </script>

    <style lang="scss" scoped>
      #app {
        font-family: 'Avenir', Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-align: center;
        color: #E3F2FD;
      }

      .md-tabs {
        background: #42A5F5;
        color: #E3F2FD;
      }

    </style>

Answer №1

This issue revolves around the concept of CSS Specificity.

Take a look at the DOM structure:

<div data-v-7ba5bd90 id="app">
  <div data-v-7ba5bd90 class="md-tabs md-alignment-left md-theme-default">
    <div class="md-tabs-navigation md-elevation-0">
      <button type="button" class="md-button md-theme-default md-active">
        <div class="md-ripple">
          <div class="md-button-content">Home</div>
        </div>
      </button>
      ...

The style rule .md-tabs { color: #E3F2FD; } is affecting the

<div data-v-7ba5bd90 class="md-tabs md-alignment-left md-theme-default">
element (line 2).

However, the specificity of the button element's styling (line 4) takes precedence over the

<div class="md-button-content">Home</div>
content (line 6).

As for the background, although

.md-tabs { background: #42A5F5; }
is present, it doesn't affect the appearance because the actual color applied to the button is transparent as defined in .md-button. Therefore, the button appears transparent, while its parent div receives the color.

Solution:

If you try adding

.md-button-content { color: #E3F2FD }
, it won't take effect due to Vue automatically applying
.md-button-content[data-v-12345] { color: #E3F2FD }
, which the inner
<div class="md-button-content">Home</div>
lacks.

To resolve this, you need to create a non-scoped <style> tag and include the following:

<style lang="scss" scoped>
...
</style>

<style>
    .md-button-content {
       color: #E3F2FD;
    }
</style>

Demo: https://codesandbox.io/s/4q8jzq9mzx?module=%2Fsrc%2FApp.vue

Answer №2

Each component has its own unique scope, so any CSS applied outside of it will not affect the component.

To style your components, it is recommended to apply CSS within the component itself or utilize a global CSS file for all components.

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

Ways to customize the border of the ListItemButton when it's in a selected state using Material UI?

I'm currently working on a feature that involves highlighting a ListItemButton with a specific background color when selected. However, I now want to take it a step further and add an outline or border color around the ListItemButton when it is select ...

What steps can be taken to encourage a client to download a file from a webpage that is password-protected?

I've encountered a challenge with my FTP server, as it is password protected and I want users to be able to download from it via a button on my website without revealing the password. Currently, I am using puppeteer to bypass the authentication proces ...

Optimizing CSS for printing by eliminating unnecessary white space with media queries

Appreciate your assistance! I'm currently working on a solution to print a specific div using CSS Media queries. When the user clicks on print, I want to hide all other elements except for the body div they chose. However, I'm facing an issue whe ...

Confusion between Codeigniter's URL and base_url() function

$config['base_url'] = 'localhost/project'; <link href="<?= base_url(); ?>/css/bootstrap.min.css" rel="stylesheet"> An issue arises with the CSS not loading on the view due to a double '/' in the URL. This occur ...

Tips for arranging files within a directory in Netbeans IDE

I prefer to centralize all CSS files in a single folder for easy access. Below is the path of my CSS directory: css/sampl.css. Here, css represents the folder. This is the code snippet I am using: <link href="/CSS/sampl.css" rel="stylesheet" type="te ...

Utilizing a CSS stylesheet within an ASP.NET platform

In my website, I have a reference to a CSS file like the one below: <link rel="stylesheet" type="text/css" href="http://go/css/filename.css"> Now, I want to make changes to this CSS file and upload it to a new location. Can I store the modified fi ...

I successfully managed to ensure that the splash screen is only displayed upon the initial page load. However, I am now encountering an issue where it fails to load again after I close the page. Is there any possible solution

After successfully implementing a splash screen that only plays once on page load, I encountered an issue. When I close the tab and revisit the page, the splash screen no longer plays. Is there a way to fix this problem? Perhaps by setting a time limit for ...

Aligning Content in the Center of a CSS Grid

Having difficulty with a CSS Grid layout that should consist of 7 squares per row to create a calendar style design. The layout seems fine, but I am struggling to center the title and subtitle in the middle of each item. I have tried using margin:auto, ver ...

Using Vue.js, pull information from a database to populate input fields using a datalist feature

I'm currently working on a project utilizing Laravel 8 and Vue 3, and I have a Student Component. Within this component, there is a datalist that allows me to search for existing students. When I select a student from the list, I want the correspondin ...

How to activate PurgeCSS for external CSS sources

I have integrated the @mdi/font into my project built with Nuxt for server-side rendering (SSR). Is there a way to enable purgeCSS specifically for the CSS coming from @mdi/font? nuxt.config.js module.exports = { css: [ '@/assets/scss/a ...

Module repository reverting to original state

I'm currently grappling with the concept of resetting VueX store when the state is modularized. Here's the structure I'm working with: └── store ├── index.js └── module-cart ├── index.j ...

A guide to efficiently filling multiple rows of images with different heights while preserving their aspect ratio

I am facing a design challenge that I believe can be solved using CSS, although it might require some Javascript. My issue involves a gallery of images with varying sizes and proportions. I would like to achieve the following: Distribute the images in m ...

Using Accordions in Jquery to dynamically adjust page height during ajax calls

I am currently using AJAX to call in a page and animate its height successfully. However, I have encountered an issue with an accordion-like function that is supposed to toggle the visibility of an element and adjust the height of the containing element ac ...

I am experiencing issues with the HTML footer not displaying correctly on my website

My GitHub Pages hosted website is giving me trouble with the footer styling. No matter what I try, I can't seem to get the background color to show up: h1 { background-color: #000000; } I'm attempting to create a footer similar to the one at ...

Incorporating styling preferences within a directive's template

One of the directives I am currently working on looks like this: app.directive('MessageChild', function($timeout) { return { restrict: 'E', scope: { pos: '=?', msg: '=' ...

How to implement a for loop within a Vue.js method

Within Vuejs, I have a method that updates multiple variables based on user selection. methods: { updateChart(){ this.chart1.series[1].data = [this.$store.state.selectedcities[0].value[1]]; this.chart1.series[2].data = [this.$store.state.selecte ...

How can one efficiently update numerous data properties in a Vue.js application?

My information is as follows: data() { return { monday_start: '', monday_end: '', tuesday_start: '', tuesday_end: '', wednesday_start: '', ...

Enable only the current week days on the multiple date picker feature

Can anyone recommend a date picker that only shows the current week and allows for multiple date selections by the user? I found this jsfiddle which limits the display to the current week, but it doesn't support selecting multiple dates. I attempted ...

Utilizing Vue to create a button within a popup window

Utilizing the vue2-google-maps package, I have created a custom popup. Within this custom popup, there is a button that is intended to open a new popup in place of the existing one. Here is the HTML code: <gmap-info-window :options="infoOptions" : ...

Is it possible to utilize types as constants in a switch statement?

In my file called checkoutTypes.ts, I have defined some checkout types like this: export type CheckoutInvoiceAddressSection = "InvoiceAddress"; export type CheckoutDeliveryAddressSection = "DeliveryAddress"; export type CheckoutDelivery ...