What is the process for customizing the pagination color in bootstrap-vue?

I attempted to modify it using various bootstrap examples but was unsuccessful.

        <b-pagination
            v-model="currentPage"
            :total-rows="users.length"
            :per-page="perPage"
            align="fill"
            size='lg'
            first-number
            last-number
            class="my-0"
        ></b-pagination>

Answer №1

Customizing with SCSS

If you are using SCSS, it's recommended to utilize the SCSS variables provided by Bootstrap for customizing pagination. Troy mentioned this in a comment.

Explore the available variables here.

Applying CSS Classes

You can assign a class to b-pagination and then target the a tags within the pagination using that class. A sample code snippet is included below for reference.

In addition, starting from version 2.3.0, you can use specific props to apply classes to different types of buttons. These props will add the class to the li element, so additional CSS targeting the a tag will still be necessary. For detailed information on these class props, refer to the reference section.

page-class
first-class
last-class
prev-class
next-class
ellipsis-class

If you are employing a scoped style tag within your components, make sure to use a deep selector to correctly target the a tags.

new Vue({
  el: '#app'
})
.customPagination > li > a {
  color: red;
}

.customPagination > li.active > a,
.customPagination > li > a:hover
{
  color: white;
  background-color: green!important;
}
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e1979484a1d3cfd7cfd0d0">[email protected]</a>/dist/vue.min.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e0828f8f949394928190cd969585a0d2ced4ced1">[email protected]</a>/dist/bootstrap-vue.js"></script>

<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65070a0a11161117041525514b514b54">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a3c1ccccd7d0d7d1c2d38ed5d6c6e3918d978d92">[email protected]</a>/dist/bootstrap-vue.css" rel="stylesheet"/>


<div id="app">
  <b-pagination
    :total-rows="50"
    :per-page="5"
    class="customPagination"
  >
  </b-pagination>
</div>

Answer №2

Although Bootstrap-vue may not offer much flexibility when it comes to changing the default theme colors, it is definitely achievable.

To begin, you need to create a custom.scss file where you can introduce new color themes for your bootstrap-vue setup.

In the src/assets/styles/custom.scss file:

// Define / adjust color variables
$myCustom: rgba(64, 206, 148, 1);
$primary: $myCustom;

Keep in mind that in the example provided above, all bootstrap elements - including pagination components - without a specified variant will adopt the $myCustom color scheme.

Next, import this custom file along with the original SCSS bootstrap file into your main Vue component:

<style lang="scss">
 @import "./assets/styles/custom.scss";
 @import "../node_modules/bootstrap/scss/bootstrap.scss";
</style>

In your code snippet, make sure to specify the variant accordingly:

<b-pagination
    v-model="currentPage"
    :total-rows="users.length"
    :per-page="perPage"
    align="fill"
    size='lg'
    first-number
    last-number
    class="my-0"
    variant="primary"
></b-pagination>

If you prefer not to alter the default primary color, you can establish a new variant within your custom.scss file:

$theme-colors: ( "newVariant": rgba(0, 152, 152, 1));

We hope this solution meets your requirements perfectly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to access information and functions from another component

Creating a timer dashboard where alarms can change the background color of the timer. Looking to display the timer on a different page with the set background color from the dashboard, but struggling to pass data between components successfully. http ...

What could be causing React onclick events to not trigger when wrapped within a Vue application? (No additional libraries)

As I dive into the world of combining React and Vue components, I encountered an interesting challenge... const RootTemplate = () => { return ( <div id="vue-app"> ... <IconButton color="inherit" onClick={thi ...

Is Axios phasing out support for simultaneous requests?

According to the current axios documentation, there is a section that is not very well formatted: Concurrency (Deprecated) It is advised to use Promise.all instead of the functions below. These are helper functions for managing concurrent requests. axio ...

Steps for launching a hyperlink in a browser on Vue Native

I'm having trouble finding information on how to properly use the Linking component in react-native. The resources available are limited, and I'm not sure if I am implementing it correctly... Below is what I have in my template: <nb-button :o ...

Dynamically importing files in Vue.js is an efficient way to

Here's the code snippet that is functioning correctly for me var Index = require('./theme/dir1/index.vue'); However, I would like to utilize it in this way instead, var path = './theme/'+variable+'/index.vue'; var Inde ...

Exploring the discrepancies in utilizing the i18n library versus directly incorporating locale from JSON in vue.js

Recently, I decided to incorporate Chinese language into my Vue app. To achieve this, I loaded the entire JSON text into Vuex and utilized the stored text directly, instead of relying on an i18n library. I'm curious to know if there are any potential ...

Splitting files with Webpack generates dynamic chunk files

Anticipating to only have two distinct chunks named vendors and commons, webpack unexpectedly generates a new chunk file for specific entries with a delimiter. optimization: { splitChunks: { chunks: 'all', cacheGroups: { ...