bootstrap-vue 改变 <b-modal> 的位置

新手上路,请多包涵

默认情况下 <b-modal> 显示在页面顶部。当属性 centered 添加到标签时。它居中。

但是,我想在页面顶部下方显示具有一定间隙的模态。

打开主页时会显示模态框。

AppModal.vue

 <template>
<b-modal ref="thisModalRef" :modal-class="my-modal" size="lg" hide-header hide-footer no-close-on-backdrop hide-header-close>
    //...
</b-modal>
</template>
<script>
export default {
  data () {
    return {
      mymodal: ['mymodal']
    }
  },
  methods: {
    hideModal () {
      this.$refs.thisModalRef.hide()
    },
    showModal () {
      this.$refs.thisModalRef.show()
    }
  }
}
</script>

<style scoped>
  .mymodal > div {
    position: absolute;
    top: 300px;
    right: 100px;
    background-color: yellow;
  }
</style>

AppHome.vue

 <template>
  <div>
    // omitted
    <AppModal ref="modalRef"></AppModal>
  </div>
</template>

<script>
import AppModal from './AppModal'

export default {
  components: {
    AppModal
  },
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  },
  methods: {
    showModal: function () {
      this.$refs.modalRef.showModal()
    }
  },
  mounted () {
    this.showModal()
  }
}
</script>

<style scoped>
// ommitted
</style>

modal相关的html源码

<div id="__BVID__16___BV_modal_outer_">
   <div id="__BVID__16" role="dialog" class="modal fade show d-block mymodal" style="padding-right: 15px;">
      <div class="modal-dialog modal-lg">
         <div tabindex="-1" role="document" aria-describedby="__BVID__16___BV_modal_body_" class="modal-content">
            <!---->
            <div id="__BVID__16___BV_modal_body_" class="modal-body">
               // ommitted
            </div>
            <!---->
         </div>
      </div>
   </div>
   <div id="__BVID__16___BV_modal_backdrop_" class="modal-backdrop fade show"></div>
</div>

如您所见, mymodal 类已正确应用。但是 div .modal-dialog 没有我给它的 css 属性。

在开发工具中找到的真正的 CSS 属性

.modal-dialog {
    position: relative;
    width: auto;
    margin: 0.5rem;
    pointer-events: none;
}

我尝试将自定义类添加到 <b-modal> 并设置样式。没有任何效果。请帮忙。

原文由 Minjun Yu 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
1 个回答

我用

<b-modal
    body-class="modalcart"
    ref="addToCart"
    id="addToCarModal"
    hide-footer
    hide-header
>
<b-container class="text-center modal-product-content">
  <img class="modal-image" src="~/assets/images/add-to-cart.png" alt=""/>

和:

 <style lang="scss" scoped>
/deep/ .modalcart {
  font-family: 'poppins-bold';
  /deep/ .modal-product-content {
    padding: 3rem;
    margin: 0 auto !important;
    /deep/ .modal-image {
      height: 150px;
      margin-bottom: 2rem;
      }
    }
  ...
  }
  </style>

和工作!谢谢

请记住,没有 body-class 和 /deep/ 将无法工作我使用 node-sass、vue 3、vue-loader 15

原文由 evavargas 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题