Resolving conflicts between Bootstrap and custom CSS transitions: A guide to identifying and fixing conflicting styles

I am currently working on implementing a custom CSS transition in my project that is based on Bootstrap 3. The setup consists of a simple flex container containing an input field and a select field. The functionality involves using jQuery to apply a .hidden class to the input field when a specific value is selected from the dropdown. This class modifies the flex-base property of the input field, causing it to be hidden with a smooth transition. When a different value is selected, the field should reappear.

While everything functions properly in a basic HTML test file, the problem arises when I include the bootstrap.css link in the header. The transition stops working, and the input field no longer hides/shows smoothly as intended.

How can I identify the portion of bootstrap.css responsible for this issue and resolve it? Despite spending considerable time analyzing the bootstrap files, I have been unable to find a solution so far.


Please select "Value A" from the dropdown below to observe the issue...

Working Fiddle: https://jsfiddle.net/gd03sjtn

Fiddle with Bootstrap (not working): https://jsfiddle.net/gd03sjtn/1

Check out the two code snippets illustrating the functioning and non-functioning states (affected by bootstrap css)

$(function() {
var $typeSelect = $('#typeSelect');
var $valueSpinner = $('#valueInput');

$typeSelect.change(function() {
if ($typeSelect.val() == "0") {
$typeSelect.addClass('red');
$valueSpinner.parent().addClass('hidden');
} else {
$typeSelect.removeClass('red');
$valueSpinner.parent().removeClass('hidden');
}
});
});
.container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}

.container select {
flex-grow: 10;
}

.container select.red {
background: red;
}

.container .spinner {
flex-grow: 0;
flex-basis: 30%;
transition: flex-basis 500ms ease-in-out;
}

.container .spinner.hidden {
flex-basis: 0%;
}

.container .spinner input.valueInput {
width: 100%;
}
<!-- Remove Bootstrap.css to make this working -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<div class="container">
<span class="spinner">
<input id="valueInput" value="205" class="valueInput">
</span>

<select id="typeSelect">
<option value="0">A</option>
<option value="1">B</option>
<option value="2">C</option>
<option value="3" selected="selected">D</option>
<option value="4">E</option>
</select>
</div>

$(function() {
var $typeSelect = $('#typeSelect');
var $valueSpinner = $('#valueInput');

$typeSelect.change(function() {
if ($typeSelect.val() == "0") {
$typeSelect.addClass('red');
$valueSpinner.parent().addClass('hidden');
} else {
$typeSelect.removeClass('red');
$valueSpinner.parent().removeClass('hidden');
}
});
});
.container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}

.container select {
flex-grow: 10;
}

.container select.red {
background: red;
}

.container .spinner {
flex-grow: 0;
flex-basis: 30%;
transition: flex-basis 500ms ease-in-out;
}

.container .spinner.hidden {
flex-basis: 0%;
}

.container .spinner input.valueInput {
width: 100%;
}
<!-- Remove Bootstrap.css to make this working -->
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<div class="container">
<span class="spinner">
<input id="valueInput" value="205" class="valueInput">
</span>

<select id="typeSelect">
<option value="0">A</option>
<option value="1">B</option>
<option value="2">C</option>
<option value="3" selected="selected">D</option>
<option value="4">E</option>
</select>
</div>

Answer №1

It appears that the issue stems from using the same class name as one in bootstrap:

hidden { display: none!important }

As a result, your spinner flex panel is not shrinking to flex-basis: 0% - instead, it is disappearing completely and immediately.


How can I identify which part of bootstrap.css is causing this and resolve the issue?

Firstly, try assigning different class names in your own CSS - I changed hidden to hiddenx in your JS+CSS files, and it resolved the problem.

Secondly, inspect the Elements/Styles tab/sub-tab in developer tools (F12) to observe how styles are being altered.

Additionally, having some knowledge about the styles used by bootstrap, such as hidden concealing elements, helped pinpoint the root of the problem without needing to sift through the entirety of bootstrap's CSS file.

Answer №2

Whenever you request to retrieve all CSS rules for Bootstrap:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

this particular link in the header will consolidate all other configurations in your CSS...

Solution:

Simply download the compiled bootstrap.min.css file and customize it according to your specific requirements!

Link to download customized Bootstrap CSS

Answer №3

To enhance your web development skills, I recommend utilizing the developer tools (F12) available in browsers such as Firefox or Chrome. Within the "elements" tab (referred to as such in Chrome - the terminology may vary in Firefox), navigate to the element you are working with that requires a CSS transition. Click on the element and view the styles displayed on the right side in the style-area. The highest precedence selector is listed at the top. If you need clarification on which value for a specific CSS attribute is being used, switch over to the Computed tab.

Both sections display the applied styles along with details on their origin from the stylesheet and line number.

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

Collecting the timestamp when the page is loaded and then comparing it with the timestamp when the form is

I have implemented an anti-spam time trap in my application (although I realize its effectiveness may not be 100%, it serves as a temporary solution) that functions as follows: 1) Upon loading a page, a hidden input is populated with a timestamp using Jav ...

Could not locate the CSS file within the HTML document (404)

I've searched high and low on YouTube but can't seem to find a solution to this problem. Every time I run the code, it gives me an error message saying GET net::ERR_ABORTED 404 (NOT FOUND) <html> <head> <title>itays websit ...

What is the best way to retrieve a JSON key in ReactJS?

I am currently facing a rendering issue. In my componentDidMount function, I am using axios to make a GET call and then updating the state with the received JSON data. The problem arises when I try to access the keys of the JSON in the render method becau ...

Dealing with errors in Node.js using the Express framework and the

The code I'm having trouble with is shown below app.get('/', function(req, res, next) { if (id==8) { res.send('0e'); } else { next(); } }); app.use(function(err, req, res, next){ res.send(500, ' ...

Having trouble capturing the CHANNEL_ANSWER event in my node.js script when communicating with Freeswitch

Greetings to all! I have a query regarding freeswitch. Although my experience with freeswitch is limited, I am currently working on connecting my node js script to the freeswitch server. So far, I have managed to establish a successful connection and gene ...

The system encountered an issue: "Property 'add' is not defined and cannot be read."

I'm facing a dilemma with my exercise. Despite the numerous inquiries regarding this problem, I haven't been able to find a solution. I am hopeful that you can provide some assistance! Below is the code snippet in question: let myDivs = docume ...

Ensure that each item rendered in a VUE.js v-for loop is distinct and not repetitive

I have obtained a JSON formatted object from a Web API that contains information about NIH funding grants. Each grant provides a history of awards for a specific researcher. My goal is to display only the latest award_notice_date for each unique project ...

Struggling with css margins and div image constraints, seeking guidance and tips for resolution

Struggling with creating a dynamic gallery that works smoothly in jsfiddle but encounters multiple issues when integrated into WordPress. The main problem is the excessive stretching of margins between image titles and meta-data, leading to misalignment an ...

Pass on only the necessary attributes to the component

I have a simple component that I want to include most, if not all, of the default HTML element props. My idea was to possibly extend React.HTMLAttributes<HTMLElement> and then spread them in the component's attributes. However, the props' ...

Action creator incomplete when route changes

In my React-Redux application, there is an action creator that needs to make 4 server calls. The first three calls are asynchronous and the fourth call depends on the response of the third call. However, if a user changes the route before the response of t ...

What is the best way to restrict the number of columns in a card-deck layout?

I'm facing an issue with my code where I want to display only four columns in a row, not more or less. Currently, the number of cards range from 1-10 and they keep compressing until there are 10 cards in a row. <div class="card-deck-wrapper"> ...

Utilizing the power of Ajax for enhancing table sorting and filtering functionality

Having an issue using JQuery tablesorter to paginate a table with rows fetched from the database. //list players by points (default listing) $result=mysql_query("select * from players order by pts_total") or die(mysql_error()); echo "<table id='li ...

When working with Express router callbacks, the Array.includes() method will always return false, the Array.indexOf() method will always return -1, and

After utilizing fs.readFile() and fs.readFileSync() functions to access the content of 'words_alpha.txt', I discovered that the file can be accessed publicly from this link: https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha. ...

Adding an HTML string to the head in Next.js

Every time I fetch data from an API, it returns an object with the property head: '<title>dummy title<title>' Despite trying different methods, I am unable to display this HTML string in the head tag. This is my code: <Head>{da ...

Updating a Rails partial using JSON response from an AJAX post request

I recently implemented an AJAX post request in my backend Rails application to upload a file. Upon successful posting, the response contains a JSON list of files. Now, I face the challenge of reloading the file list on my 'detalhes.html.erb' vie ...

Building module dependencies in the Dojo dojo

I'm in the process of utilizing the Dojo builder to compile a unified file that encompasses all the necessary modules for my application, excluding the application itself. Below is an illustration of a layer definition: layers: { 'dojo/dojo ...

What are some javascript libraries that can be used to develop a mobile image gallery for both Android and iPhone

I currently have the touch gallery system in place, but unfortunately it isn't functioning properly on Android devices. ...

Is it possible to use jQuery to load a page via AJAX and define a callback function on the loaded page

Currently, I am using the $('#container').load method to manage loading all the subpages of my website. However, some of these sub-pages require additional functionality such as form validation. I would like each sub-page to be self-contained, m ...

Using a for loop, how can the property value be set in another object?

One challenge that I am facing is setting object property values. The object in question looks like this: const newPlan = { name: '', description: '', number: '', monday: { breakfast: '', ...

How come my Ajax call is setting the 'Content-Type' to 'application/x-www-form-urlencoded' instead of 'JSON' as specified in the dataType parameter?

I have encountered an issue while responding to a button click using the code snippet below. The console.log() confirms that the function is being called, but the HTTP request it generates contains the header "Content-Type: application/x-www-form-urlencode ...