css - 如何覆盖 b-modal 中的 vue-bootstrap 样式

标签 css vue.js bootstrap-vue

我尝试使用 bootstrap-vue 更改 b-modal -> in .modal-header 中的背景颜色.但是 vue 没有看到我的样式,我不知道为什么:/
这是代码。我按照 link 中的回答

HTML:

b-modal(id="card-1" title="CARTÃO DE CRÉDITO"  :modal-class="myclass" header-text-variant="light")

VUE
export default {
    data: {
   myclass: ['myclass']
 },

}

CSS
.myclass > .modal-dialog > .modal-content > .modal-header {
  background-color: #da2228 !important;
  color: white;
}

但我仍然没有看到结果。模态标题为白色。任何想法为什么?

最佳答案

您可能正在使用 scoped您的 .vue 中的样式标签文件。
如果是,则需要使用 deep-selector正确定位子组件。

选择器是 /deep/ , >>>::v-deep .
在下面的例子中,我使用 /deep/ ,但其他人也应该为你工作。

您也可以使用 header-class支持 b-modal如果您愿意,可以直接将类添加到标题中。

<template>
  <b-modal header-class="my-class">
    <template #modal-header>Header</template>
    Hello
  </b-modal>

  <b-modal modal-class="my-second-class">
    <template #modal-header>Header</template>
    Hello
  </b-modal>
</template>

<style scoped>
/deep/ .my-class {
  background: black;
  color: white;
}

/deep/ .my-second-class > .modal-dialog > .modal-content > .modal-header {
  background: black;
  color: white;
}
</style>

关于css - 如何覆盖 b-modal 中的 vue-bootstrap 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61007101/

相关文章:

html - 联系表 7 - 选择选项透明

html - 跨度内文本的垂直对齐 - 跨度外的文本

iphone - 单击选择按钮时滚动条未加载到 iPad 上

javascript - 嵌套表单 - vue

vue.js - VueJs 3 :vue-router change query and use router. Push() 但 url 不更新

javascript - 如何观察javascript数组中对象的变化?

javascript - Vue.js - 观察数据变化

css - 如何在 Bootstrap-Vue 中增加工具提示的宽度

javascript - 非被动滚动事件处理程序的控制台警告

html - 使用 HTML 和 CSS 将背景图像与图像对齐