vesii
vesii

Reputation: 3128

Creating a complicated panel using Bootstrap-Vue

Based on my previous question on Vue-Bootstrap panel I started using the following code to create a panel:


<b-card no-body class="mb-1">
    <b-card-header header-tag="header" class="p-1" role="tab">
        <b-button block disabled href="#" v-b-toggle.accordion-1 variant="info">Search:</b-button>
    </b-card-header>
    <b-collapse id="accordion-1" visible accordion="my-accordion" role="tabpanel">
        <b-card-body>
            <search-form :fieldList="fieldList" :customs-max-num="customsMaxNum" :data-types="dataTypes" />
        </b-card-body>
    </b-collapse>
</b-card>

As you can see, I a button as a header. But what If I want to do something more complicated? For example I want to create the following header:

enter image description here

As you can see, this header contains a title and a button. If I do it as I did before, I will have a button and text on a button? Does not feels right. What I currently have:

<b-card no-body class="mb-1">
    <b-card-header header-tag="header" class="p-1" role="tab">
        <div class="title align-left" height="100px">
            <button class="pull-right btn btn-info" @click="goBack()">Go Back</button>
            <strong>Data run:</strong>
            {{ title() }} <br> {{ subtitle() }}
        </div>
    </b-card-header>
    <!-- BODY -->
</b-card>

How it looks like:

enter image description here

How do I create such panel?

Upvotes: 0

Views: 289

Answers (1)

Hiws
Hiws

Reputation: 10324

You can achieve this look by using display: flex on your header. Add the class d-flex to your header and wrapping your button in a div and giving it the class ml-auto, this class applies the style margin-left: auto;

Using margin-left: auto inside display:flex will fill up the empty space with a margin, pushing the content in the opposite direction.

<b-card no-body class="mb-1">
  <b-card-header header-tag="header" role="tab" class="d-flex">
    <div class="title align-left" height="100px">
      <strong>Data run:</strong> Title<br> 
      Subtitle
    </div>
    <div class="ml-auto">
      <button class="btn btn-info">Go Back</button>
    </div>
  </b-card-header>
</b-card>

new Vue({
  el: "#app"
});
<link href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="//unpkg.com/[email protected]/dist/bootstrap-vue.min.css" rel="stylesheet" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.js"></script>
<script src="//unpkg.com/[email protected]/dist/bootstrap-vue.min.js"></script>

<div id="app">
  <b-card no-body class="mb-1">
    <b-card-header header-tag="header" role="tab" class="d-flex">
      <div class="title align-left" height="100px">
        <strong>Data run:</strong> Title<br> 
        Subtitle
      </div>
      <div class="ml-auto">
        <button class="btn btn-info">Go Back</button>
      </div>
    </b-card-header>
  </b-card>
</div>

Upvotes: 1

Related Questions