How can we stop Vuetify from overwriting Bootstrap3's classes when using treeshaking?

I am currently in the process of transitioning an app from jQuery/Bootstrap3 to Vue/Vuetify. My approach is to tackle one small task at a time, such as converting the Navbar into its own Vue component and then gradually updating other widgets.

Since the navbar is globally loaded on every page, Vuetify's styles are conflicting with Bootstrap3 styles (like .row, etc). I have intentionally opted not to utilize Vuetify's row, container, or similar components, sticking solely to the components listed in my custom vuetify.js setup.

Is there a way to prevent Vuetify's styling from interfering with Bootstrap? I have configured Vuetify with tree shaking and only imported necessary components in my vuetify.js file:

import Vue from 'vue';
import Vuetify, {
  VApp,
  VCheckbox,
  VRadio,
  VSelect,
  VSwitch,
} from 'vuetify/lib';

Vue.use(Vuetify, {
  components: {
    VApp,
    VCheckbox,
    VRadio,
    VSelect,
    VSwitch,
  },
});

const opts = {};

export default new Vuetify(opts);

Then, using Vue.extend, I extend the NavbarApp:

const NavbarAppRoot = Vue.extend(NavbarApp);

Lastly, I incorporate it into my Navbar app along with other elements like this:

new NavbarAppRoot({
  el: navbarAppRootEl,
  store,
  vuetify, // <-- referring to the above vuetify.js
  propsData: {
    lang: config.lang,
  },
  i18n,
});

It is important to note that I am not importing vuetify.min.css anywhere in the codebase.

To illustrate the conflict between Vuetify and Bootstrap, here is a screenshot: https://i.stack.imgur.com/EWXzs.png

Any suggestions on how to prevent Vuetify's styles from taking precedence over crucial Bootstrap3 styles during this transition phase?

Answer №1

Regrettably, the most effective solution in this scenario is the less aesthetically pleasing one. It involves manually applying the same classes that Bootstrap uses after Vuetify has been loaded.

To address this issue, I have created some global .scss files that are loaded post-Vuetify - specifically a vuetify-overrides.scss file that mirrors all of Bootstrap's container, row, col-* classes, and more. While not visually appealing, this approach does work and prevents your styles from becoming disordered.

NOTE: If you have modified any default variables for Bootstrap such as padding, margin, or grid values, then you will need to generate your customized file by inspecting dev tools and manually copying the displayed output. Keep in mind that creating higher-order CSS variables for this file may be necessary if you intend to easily adjust these variables later on!

.container {
  padding: 0 15px;
  margin-right: auto;
  margin-left: auto;
}
@media (min-width: 768px) {
  .container {
    width: 750px;
  }
}
@media (min-width: 992px) {
  .container {
    width: 970px;
  }
}
@media (min-width: 1200px) {
  .container {
    width: 1170px;
  }
}
.container-fluid {
  padding: 0 15px;
  margin-right: auto;
  margin-left: auto;
}
...
(remaining content omitted for brevity)
...

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

Obtaining the text of a span tag within a div using Selenium in C#

<div id="uniqueSummaryID" class="custom-text" data-reactid=".0.0.0.3.0.0.1.0.0.0.0.$unique_key_25.1.1.0"> <span data-reactid=".0.0.0.3.0.0.1.0.0.0.0.$unique_key_25.1.1.0.0">5</span> <span data-reactid=".0.0.0.3.0.0.1.0.0.0.0.$unique_ke ...

Issue with Laravel: Validation unique during update process consistently not working

Recently, I encountered a puzzling issue with my update form which includes an image and other data that needs to be updated. I decided to change the default route key from ID to name, and also set up a separate form request for validating requests. Everyt ...

The installation of vue-cli using npm has been successfully completed and now supports coffeescript integration

After numerous attempts to set it up using various versions of nodejs / npm and multiple hosts, I even tried installing it on a docker image: Sending build context to Docker daemon 2.048kB Step 1/4 : FROM node:slim ---> c4e99b1ed64f Step 2/4 : RUN np ...

Is it feasible to combine border-radius with a gradient border-image?

I'm trying to style an input field with a rounded border using the border-radius property, and also add a gradient to that border. Despite successfully creating both the gradient and rounded corners separately, I am unable to make them work together. ...

Create a dynamic effect by adding space between two texts on the page

const Button = () => { const options = ['test1', 'test2', 'test3']; return ( <div style={{ position: 'absolute', left: '8px', width: 'auto', flexDirection: 'row' ...

The feature in Chrome that automatically reloads generated CSS is failing to refresh the page after SASS recompiles the CSS

I'm attempting to set up Chrome's DevTools to automatically reload a page when I save changes to a watched SCSS file that compiles and updates the CSS file. Although I have checked the Auto-reload generated CSS option, it is unfortunately not fu ...

access search input value in Vuetify combobox on blur event

In my v-combobox, I can easily select or deselect multiple items from a list of objects. <div id="app"> <v-app> <v-layout column> <v-form v-model="valid"> <v-combobox v-model="selectedItems" ...

Having difficulty accessing the ::after element on Firefox when attempting to click

I've encountered an issue with my HTML and CSS code - it functions perfectly on Chrome, yet behaves differently on Firefox. button#groupToggle { background: 0 0; border: 1px solid #e6e6ed; color: #222; float: none; margin: 0 0 ...

Chrome Bug with Fixed Position Background

Just finished creating a website that features fixed images as backgrounds with text scrolling on top of them. I've noticed an issue when using Chrome - the scrolling stops briefly between backgrounds, pauses for about a second, and then resumes. I&ap ...

Using data variables as arguments in the style section of Vue2

Suppose we have a data variable and I want to utilize this data variable for styling purposes. data() { return{ selected:{ index: 2 } } } <style> .parent-table >>> .table-row:nth-child(/* here I intend to use ...

How to vertically align the elements within a DIV in jQuery Mobile

Is there a way to vertically align the content of a jQuery grid's block so that it is centered with another element in the same row? <div class="ui-grid-a" style="border:1px solid"> <div class="ui-block-a" style="vertical-align:middle" >& ...

What's the best way to constrain a draggable element within the boundaries of its parent using right and bottom values?

I am currently working on creating a draggable map. I have successfully limited the draggable child for the left and top sides, but I am struggling to do the same for the right and bottom sides. How can I restrict the movement of a draggable child based o ...

Restricting zooming to only occur within the img element in a UI

Is there a method to enable image zoom inside specific divs without affecting the overall page zoom? At the moment, I have: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale ...

Tips for Providing Real-Time Data for a Dynamic Chart in d3

I have a line chart sample from D3, and the issue I'm facing is that I need to continuously feed live data from a server at certain time intervals and use D3 to draw the chart based on this dynamic data. Despite my efforts to search for a solution, I ...

Tips for toggling the visibility of a <div> element with a click event, even when there is already a click event assigned

No matter what I try, nothing seems to be working for me. I'm looking to hide the <div id="disqus_thread"> at first and then reveal it when I click on the link "commenting", after the comments have loaded. This particular link is located at the ...

What is the best way to detect the window scroll event within a VueJS component?

Looking to capture the window scroll event in my Vue component. This is what I have attempted so far: <my-component v-on:scroll="scrollFunction"> ... </my-component> I have defined the scrollFunction(event) in my component methods, but it ...

Identify the CSS Framework being used in conjunction with Selenium

I have developed a program that crawls through various web pages and conducts tests using Selenium. My current task is to identify which CSS Frameworks are utilized on these websites for statistical analysis. Currently, I am using the FireFox Webdriver to ...

Video tag with centered image

For a current project, I am in need of rendering a centered image (a play button) at runtime on top of a video based on the UserAgent. If the userAgent is not Firefox, I want to display the image as Firefox has its own playEvent and button on top of the vi ...

Align the text to the right within a display flex container

Below is the code snippet: <div className="listContent"> <div> <div className="titleAndCounterBox"> <div className="headerListTitle">{list.name}</div><br /> <div ...

Head styles for tinyMCE

When viewing the tinyMCE example on the official website using Firefox, you may notice the editor blinking. This issue seems to only occur in Firefox, possibly due to external CSS files for the editor. I am considering adding all CSS rules directly into th ...