Vuetify 修改数据表格 “items-per-page” 的字体颜色。

huangapple go评论65阅读模式
英文:

vuetify changing font colors of data-table items-per-page

问题

<template>
  <div class="container fill">
    <BootstrapNavBar></BootstrapNavBar>
    <v-data-table
      :headers="headers"
      :items="desserts"
      :items-per-page="5"
      class="mytable red yellow--text"
    ></v-data-table>

 
  </div>
</template>

<script>
import BootstrapNavBar from "./BootstrapNavBar.vue";
import axios from "axios";

export default {
  components: {
    BootstrapNavBar,
  },
  data() {
    return {
      itemsPerPage: 5,
      headers: [
        {
          text: "Dessert (100g serving)",
          align: "start",
          sortable: false,
          value: "name",
          class: "white--text",
        },
        { text: "Calories", value: "calories", class: "white--text" },
        { text: "Fat (g)", value: "fat", class: "white--text" },
        { text: "Carbs (g)", value: "carbs", class: "white--text" },
        { text: "Protein (g)", value: "protein", class: "white--text" },
        { text: "Iron (%)", value: "iron", class: "white--text" },
      ],
      desserts: [
        {
          name: "Frozen Yogurt",
          calories: 159,
          fat: 6.0,
          carbs: 24,
          protein: 4.0,
          iron: "1%",
        },
      ],
      balances: [],
    };
  },
  methods: {},
};
</script>

<style scoped>
.fill {
  color: #e5e6e7;
  min-height: 100%;
  height: 100%;
}

.theme--light.v-data-table {
  background-color: #282c30 !important;
  color: rgb(255, 255, 255) !important;
}

/* Red parts trying to make white font */
.mytable .red, .mytable .yellow--text {
  color: white !important;
}

/* Selector box */
.v-select.theme--light.v-input.v-input--selection-controls.v-input--is-label-active.v-input--is-dirty {
  background-color: black !important;
}

/* Grayish color issue */
.theme--light.v-data-table {
  background-color: #282c30 !important;
  color: white !important;
}
</style>
英文:

I am struggling to find ways to change font-colors in data-table. I found ways to change color of headers and rows, but now I need to change the color of rows-per-page count selecter box (it is filled with black font, but selector box is white and fonts are black) and also < > arrow bars for page spans are left black but I want them white

&lt;template&gt;
&lt;div class=&quot;container fill&quot;&gt;
&lt;BootstrapNavBar&gt;&lt;/BootstrapNavBar&gt;
&lt;v-data-table
:headers=&quot;headers&quot;
:items=&quot;desserts&quot;
:items-per-page=&quot;5&quot;
class=&quot;mytable red yellow--text&quot;
&gt;&lt;/v-data-table&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;script&gt;
import BootstrapNavBar from &quot;./BootstrapNavBar.vue&quot;;
import axios from &quot;axios&quot;;
export default {
components: {
BootstrapNavBar,
},
data() {
return {
itemsPerPage: 5,
headers: [
{
text: &quot;Dessert (100g serving)&quot;,
align: &quot;start&quot;,
sortable: false,
value: &quot;name&quot;,
class: &quot;white--text&quot;,
},
{ text: &quot;Calories&quot;, value: &quot;calories&quot;, class: &quot;white--text&quot; },
{ text: &quot;Fat (g)&quot;, value: &quot;fat&quot;, class: &quot;white--text&quot; },
{ text: &quot;Carbs (g)&quot;, value: &quot;carbs&quot;, class: &quot;white--text&quot; },
{ text: &quot;Protein (g)&quot;, value: &quot;protein&quot;, class: &quot;white--text&quot; },
{ text: &quot;Iron (%)&quot;, value: &quot;iron&quot;, class: &quot;white--text&quot; },
],
desserts: [
{
name: &quot;Frozen Yogurt&quot;,
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: &quot;1%&quot;,
},
],
balances: [],
};
},
methods: {},
};
&lt;/script&gt;
&lt;style scoped&gt;
.fill {
color: #e5e6e7;
min-height: 100%;
height: 100%;
}
.theme--light.v-data-table {
background-color: #282c30 !important;
color: rgb(255, 255, 255) !important;
}
&lt;/style&gt;

Red parts trying to make white font
Vuetify 修改数据表格 “items-per-page” 的字体颜色。

Selector box when clicked it is black fonts over white, and selected part is all white. I need here black background, and white fonts, selected one could be another color
Vuetify 修改数据表格 “items-per-page” 的字体颜色。

also why is my data-table, grayish color. Is it possible to align it with the background fill color.

答案1

得分: 1

我明白你的意思,你想要将数据表格变成深色,包括下拉框和相关的字体、图标以及下拉项的文字要是对比度高的(白色)颜色。

通过使用以下两个技巧,你可以实现这个效果:

  1. 你不需要手动使用CSS来将表格变成深色并将内容变成白色,而是可以使用dark属性。dark属性会将表格视为深色模式,自动将字体和图标的颜色变成白色。

  2. 深色模式不会改变选择框的背景颜色。因此,你需要使用手动的CSS来实现这个效果,如下所示:

.v-sheet.v-list {
  // 这是深色模式的背景颜色
  background: #1E1E1E !important;
}
.v-list-item:not(.v-list-item--active):not(.v-list-item--disabled) {
  // 未被选中的列表项
  color: white !important;
}

这里是一个工作演示:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->
new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data() {
    return {
      headers: [{
          text: 'Dessert (100g serving)',
          align: 'left',
          sortable: false,
          value: 'name',
          class: 'white--text',
        },
        {
          text: 'Calories',
          value: 'calories',
          class: 'white--text'
        },
        {
          text: 'Fat (g)',
          value: 'fat',
          class: 'white--text'
        },
        {
          text: 'Carbs (g)',
          value: 'carbs',
          class: 'white--text'
        },
        {
          text: 'Protein (g)',
          value: 'protein',
          class: 'white--text'
        },
        {
          text: 'Iron (%)',
          value: 'iron',
          class: 'white--text'
        },
      ],
      desserts: [{
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
          carbs: 24,
          protein: 4.0,
          iron: '1%',
        },
        {
          name: 'Ice cream sandwich',
          calories: 237,
          fat: 9.0,
          carbs: 37,
          protein: 4.3,
          iron: '1%',
        },
        {
          name: 'Eclair',
          calories: 262,
          fat: 16.0,
          carbs: 23,
          protein: 6.0,
          iron: 7,
        },
        {
          name: 'Cupcake',
          calories: 305,
          fat: 3.7,
          carbs: 67,
          protein: 4.3,
          iron: 8,
        },
        {
          name: 'Gingerbread',
          calories: 356,
          fat: 16.0,
          carbs: 49,
          protein: 3.9,
          iron: 16,
        },
        {
          name: 'Jelly bean',
          calories: 375,
          fat: 0.0,
          carbs: 94,
          protein: 0.0,
          iron: 0,
        },
      ],
    }
  },
})

<!-- language: lang-css -->
.v-sheet.v-list {
  background: #1E1E1E !important;
}
.v-list-item:not(.v-list-item--active):not(.v-list-item--disabled) {
  color: white !important;
}

<!-- language: lang-html -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
</script>
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
</head>
<div id="app">
  <v-app id="inspire">
    <div class="container fill">
      <v-data-table
        :headers="headers"
        :items="desserts"
        :items-per-page="5"
        class="elevation-1"
        dark
        ></v-data-table>
    </div>
  </v-app>
</div>

<!-- end snippet -->

希望这有所帮助。

<details>
<summary>英文:</summary>

If I understood correctly, you want the data table in dark color including the dropdown and the respected fonts, icons, and dropdown items&#39; text to be in contrast (white) color.

By following these two tricks you can achieve this-
 
1. You don&#39;t need to use a manual CSS to make the table dark and its content to be white, **use a dark prop instead. The dark prop will treat the table as dark mode, which will auto-change the font and icon colors to white.**
2. Dark mode will not change the selection box&#39;s background color. So to do that, you need to use manual CSS like this-

.v-sheet.v-list {
// this is the dark mode's background color
background: #1E1E1E !important;
}
.v-list-item:not(.v-list-item--active):not(.v-list-item--disabled) {
// list items that are not selected
color: white !important;
}


Here is a working demo-
&lt;!-- begin snippet: js hide: false console: false babel: false --&gt;
&lt;!-- language: lang-js --&gt;
new Vue({
el: &#39;#app&#39;,
vuetify: new Vuetify(),
data() {
return {
headers: [{
text: &#39;Dessert (100g serving)&#39;,
align: &#39;left&#39;,
sortable: false,
value: &#39;name&#39;,
class: &#39;white--text&#39;,
},
{
text: &#39;Calories&#39;,
value: &#39;calories&#39;,
class: &#39;white--text&#39;
},
{
text: &#39;Fat (g)&#39;,
value: &#39;fat&#39;,
class: &#39;white--text&#39;
},
{
text: &#39;Carbs (g)&#39;,
value: &#39;carbs&#39;,
class: &#39;white--text&#39;
},
{
text: &#39;Protein (g)&#39;,
value: &#39;protein&#39;,
class: &#39;white--text&#39;
},
{
text: &#39;Iron (%)&#39;,
value: &#39;iron&#39;,
class: &#39;white--text&#39;
},
],
desserts: [{
name: &#39;Frozen Yogurt&#39;,
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: &#39;1%&#39;,
},
{
name: &#39;Ice cream sandwich&#39;,
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: &#39;1%&#39;,
},
{
name: &#39;Eclair&#39;,
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: 7,
},
{
name: &#39;Cupcake&#39;,
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: 8,
},
{
name: &#39;Gingerbread&#39;,
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: 16,
},
{
name: &#39;Jelly bean&#39;,
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: 0,
},
],
}
},
})
&lt;!-- language: lang-css --&gt;
.v-sheet.v-list {
background: #1E1E1E !important;
}
.v-list-item:not(.v-list-item--active):not(.v-list-item--disabled) {
color: white !important;
}
&lt;!-- language: lang-html --&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js&quot;&gt;&lt;/script&gt;
&lt;/script&gt;
&lt;head&gt;
&lt;link href=&quot;https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900&quot; rel=&quot;stylesheet&quot;&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;/head&gt;
&lt;div id=&quot;app&quot;&gt;
&lt;v-app id=&quot;inspire&quot;&gt;
&lt;div class=&quot;container fill&quot;&gt;
&lt;v-data-table
:headers=&quot;headers&quot;
:items=&quot;desserts&quot;
:items-per-page=&quot;5&quot;
class=&quot;elevation-1&quot;
dark
&gt;&lt;/v-data-table&gt;
&lt;/div&gt;
&lt;/v-app&gt;
&lt;/div&gt;
&lt;!-- end snippet --&gt;
Hope this helps.
</details>
# 答案2
**得分**: 0
```css
.theme--light.v-data-table {
background-color: #282c30 !important;
color: rgb(255, 255, 255) !important;
}
i.mdi-chevron-left, i.mdi-chevron-right, i.mdi-menu-down {
color: white !important;
}
.v-select__selections {
color: white !important;
}
英文:

Can you please try to play around with the classes mapped to the footer elements and then update the styles using custom CSS. Something like this :

i.mdi-chevron-left, i.mdi-chevron-right, i.mdi-menu-down {
color: white !important;
}
.v-select__selections {
color: white !important;
}

Demo :

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

new Vue({
el: &#39;#app&#39;,
vuetify: new Vuetify(),
data () {
return {
headers: [
{
text: &#39;Dessert (100g serving)&#39;,
align: &#39;left&#39;,
sortable: false,
value: &#39;name&#39;,
class: &#39;success--text title&#39;,
},
{ text: &#39;Calories&#39;, value: &#39;calories&#39; },
{ text: &#39;Fat (g)&#39;, value: &#39;fat&#39; },
{ text: &#39;Carbs (g)&#39;, value: &#39;carbs&#39; },
{ text: &#39;Protein (g)&#39;, value: &#39;protein&#39; },
{ text: &#39;Iron (%)&#39;, value: &#39;iron&#39; },
],
desserts: [
{
name: &#39;Frozen Yogurt&#39;,
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: &#39;1%&#39;,
},
{
name: &#39;Ice cream sandwich&#39;,
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: &#39;1%&#39;,
},
{
name: &#39;Eclair&#39;,
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: &#39;7%&#39;,
},
{
name: &#39;Cupcake&#39;,
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: &#39;8%&#39;,
},
{
name: &#39;Gingerbread&#39;,
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: &#39;16%&#39;,
},
{
name: &#39;Jelly bean&#39;,
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: &#39;0%&#39;,
},
{
name: &#39;Lollipop&#39;,
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
iron: &#39;2%&#39;,
},
{
name: &#39;Honeycomb&#39;,
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
iron: &#39;45%&#39;,
},
{
name: &#39;Donut&#39;,
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
iron: &#39;22%&#39;,
},
{
name: &#39;KitKat&#39;,
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
iron: &#39;6%&#39;,
},
],
}
},
})

<!-- language: lang-css -->

.theme--light.v-data-table {
background-color: #282c30 !important;
color: rgb(255, 255, 255) !important;
}
i.mdi-chevron-left, i.mdi-chevron-right, i.mdi-menu-down {
color: white !important;
}
.v-select__selections {
color: white !important;
}

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.1.5/dist/vuetify.min.js&quot;&gt;&lt;/script&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.1.5/dist/vuetify.min.css&quot;/&gt;
&lt;div id=&quot;app&quot;&gt;
&lt;v-app id=&quot;inspire&quot;&gt;
&lt;v-data-table
:headers=&quot;headers&quot;
:items=&quot;desserts&quot;
:items-per-page=&quot;5&quot;
class=&quot;elevation-1&quot;
&gt;&lt;/v-data-table&gt;
&lt;/v-app&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月19日 15:56:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75498726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定