Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite the vue-bootstrap styles in b-modal

I tried to change the background-color in b-modal -> in .modal-header using bootstrap-vue. But the vue doesn't see my styles and I don know why :/ here is the code. I follow by answer in 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;
}

But I still doesn't see the results. Modal header is white. Any ideas why?

like image 812
anna Avatar asked Apr 03 '20 07:04

anna


People also ask

How do I close a Bootstrap Vue modal?

$bvModal. hide() to open and close the modal respectively. They will be available when we register the BootstrapVue plugin or the ModalPlugin . We have the b-modal component, which is opened with the $bvModal.

How do I close Vue modal?

To close a modal using vue. js you can use the click event i.e. @click to trigger change in modal visibility. So, whenever the close button is pressed the @click method will trigger the function associated with the action ( here, hiding the modal ).


2 Answers

You're probably using a scoped style tag in your .vue file. If you are, then you need to use a deep-selector to properly target the subcomponent.

The selectors are /deep/, >>> or ::v-deep. In the below example i use /deep/, but the others should work for you as well.

You can also use the header-class prop on b-modal to directly add the class to the header if you wish.

<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>
like image 78
Hiws Avatar answered Oct 17 '22 08:10

Hiws


You can use content-class="your-class" in the vue bootstrap modal.

<b-modal id="myModal" content-class="your-class" title="BootstrapVue">
    Body Content
</b-modal>

Or else it is difficult to style the modal cuz the normal class="" does not apply to the code.

like image 41
Sudam Dissanayake Avatar answered Oct 17 '22 07:10

Sudam Dissanayake