Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom styles to material components without breaking anything

I am using vuejs with vuetify a material design support for vuejs, but I am confused as to how I can add custom css styles to material design without breaking a convention of the material design itself.

It is like bootstrap where we can call .row{} and override the styling or does it differ in some ways.

like image 662
hidar Avatar asked Aug 20 '17 21:08

hidar


People also ask

How do you customize material components?

To customize a specific part of a component, you can use the class name provided by Material UI inside the sx prop. As an example, let's say you want to change the Slider component's thumb from a circle to a square. First, use your browser's dev tools to identify the class for the component slot you want to override.

What is Panelclass?

The class Panel is the simplest container class. It provides space in which an application can attach any other component, including other panels. It uses FlowLayout as default layout manager.


1 Answers

I don't think there're many differences from bootstrap since vuetify will automatically add necessary class names for you. Suppose you want to override the background color of the following template.

<v-layout row justify-space-around></v-layout> 

Just override it with .row

.row {
  background: #123456;
}

Check the sample below.

new Vue({ el: '#app' })
.row {
  background: #123456;
}

.theme--dark {
  width: 400px;
}

.card__text {
  font-weight: 800;
}
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script src="https://unpkg.com/vuetify/dist/vuetify.js"></script>
<link href="https://unpkg.com/vuetify/dist/vuetify.min.css" rel="stylesheet">

  <div id="app">
    <v-app>
      <main>
      <v-layout row justify-space-around>
        <v-card dark class="primary">
          <v-card-text>one</v-card-text>
        </v-card>
      </v-layout>        
      </main>
    </v-app>
  </div>

Please notice that - was converted to __ (e.g. v-card-text) and theme-- was prepended to the theme's name (e.g. dark).

like image 86
choasia Avatar answered Oct 06 '22 01:10

choasia