Struggling to customize the style of bootstrap components

Struggling to get my custom css to take precedence over Bootstrap4 components in my Django project.

I'm a beginner in front-end development and I'm hoping to articulate my question clearly. Note: This is an HTML sheet within a Django project. My custom css sheet is linked correctly as it successfully styles other components (non-bootstrap) on the page.

The only way I've managed to override any Bootstrap components is by directly including the style as an HTML attribute, like in the example below where I set the background of the first row to blue. I've been grappling with this issue for a couple of days now, and all I seem to find is advice to ensure that your custom stylesheet is loaded after the Bootstrap stylesheet. My home.css sheet is indeed loaded after the Bootstrap CSS, but I'm unsure if the way Django loads these files is causing conflicts with the order.

Any help or suggestions on how to troubleshoot this would be greatly appreciated. Thank you.

    {% load staticfiles %}
    <head>
      <!-- Bootstrap core CSS -->
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">  </head>
      <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato&display=swap" >
      <link rel="stylesheet" href="{% static 'css/home.css' %}" >
    </head>

    <body>
    <!--#################  START OF CARD  #################-->
            {% for product in products.all %}
            <div class="card-group">
            <div class="card mb-3">
    <!-- start second row -->
              <div id = "top" style = "background: blue;" class="row no-gutters">
                <div class="col-md-6 d-flex">
                  <div class="card-img-body">
                  <img src="{{ product.img_url }}" class="card-img img-fluid">
                </div>
                </div>
                <div class="col-md-6 d-flex align-items-center">
                  <div class="card-body">
                    <h4 class="card-title text-center">{{product.title}}</h4>
                    <p class="card-text">{{product.body}}</p>
                    <p class="card-text text-right"><small class="text-muted">{{product.date_posted_pretty}}</small></p>
                  </div>
                </div>
              </div>
    <!-- start second row -->
              <div class="secondary row no-gutters d-none">
                <div class="col-md-6 d-flex align-items-center">
                  <div class="card-body">
                  <h6 class="card-subtitle text-center">{{product.product_name}}</h6>
                  <p class="card-text "><small class="text-muted">{{product.product_description}}</small></p>
                  </div>
                </div>
                <div class="col-md-6 d-flex align-items-center">
                  <div class="card-body text-center">
                  <a class="btn btn-light" href="#" role="button">Product</a>
                  <a class="btn btn-light" href="#" role="button">Homepage</a>
                  <a class="btn btn-light" href="#" role="button">Mission</a>
                  </div>
                </div>
              </div>
            </div>
            </div>
            {% endfor %}

    <!--#################  END OF CARD  #################-->
    </body>

And below is the CSS I've attempted, targeting both class and ID selectors.

    .row .no-gutters{
      background: blue;
    }

    #top {
      background: blue;
    }

Despite removing the style attribute, my expectation was for this CSS to override the Bootstrap components, but unfortunately, this is not the case.

Answer №1

Before proceeding, it is crucial to review your selectors.

.row .no-gutters represents a different selection compared to .row.no-gutters (notice the absence of a space between classes).

The former targets elements with a class of .no-gutters that are descendants of elements with the .row class. On the other hand, the latter selects elements with both the .row and .no-gutters classes simultaneously.

Answer №2

Have you experimented with this approach:

background: blue !important;

Although not recommended, this method should suffice. Alternatively, consider a more targeted approach like:

.card #top { background: blue ;}

or

div #top { background: blue;}

Answer №3

There are three ways to add CSS to HTML elements:

1. Inline - by using the style attribute in HTML elements 2. Internal - by using a element in the section 3. External - by using an external CSS file

Inline CSS is given the highest priority, which can sometimes lead to conflicts with other styles, such as bootstrap. To resolve this conflict, you may need to edit or remove the bootstrap styles.

For more information on customizing Bootstrap CSS templates, you can visit this link.

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

Compressing CSS with the help of Gulp

Can anyone assist me with minifying my css in this gulpfile.js for compiling css? I have tried multiple code snippets from the internet but none of them seem to work. Your help would be greatly appreciated. Thank you. var gulp = require('gulp&apo ...

When a cursor hovers over an image, a dark line appears

I wanted to create a hover effect where the image would enlarge when hovered over. I achieved this using a JavaScript function that applies the transform property with a scale of 1.2 to the picture. However, during the animation, a black line appears at th ...

What is the most effective approach to seamlessly conceal and reveal a button with the assistance

I have two buttons, one for play and one for pause. <td> <?php if($service['ue_status'] == "RUNNING"){ $hideMe = 'd-none'; } ?> <a href="#" class="btn btn-warning ...

Revamp selected bootstrap attribute

Imagine a scenario where there is: @media (min-width: 576px) { #projects-edit-middle-column .equal-columns-wrapper .equal-columns { width: 50%; padding-right: 25px; } } This is being utilized within a container: <div class="equal-columns ...

Clicking on a different texture/image allows for the texture to change in Three.js

I am working on creating a 360 image view using Threejs. I have a total of 4 images, with one linked to Threejs and the other 3 displayed as thumbnails at the bottom of the page. When a thumbnail is clicked, the 360 image view should change accordingly. Y ...

My current table design in bootstrap is having trouble displaying properly, with empty columns appearing when I

I'm having an issue with my table that has striped rows. The columns Name, Description, and Actions are not showing up as expected. Even though the sample codes for the table work fine, there seems to be a problem in my implementation. Can someone ple ...

Struggling to grasp the concept of DOM Event Listeners

Hello, I have a question regarding some JavaScript code that I am struggling with. function login() { var lgin = document.getElementById("logIn"); lgin.style.display = "block"; lgin.style.position = "fixed"; lgin.style.width = "100%"; ...

Guide on incorporating a glyphicon into a dropdown menu link by leveraging the link_to helper in Ruby on Rails

Just getting started here and I have a question... I want to include glyphicons on the links in a dropdown menu using the link_to helper in my Ruby on Rails app. This is the code I currently have: <ul class="nav_item pull-right"> <li cla ...

I am looking to save the session value into the search box of the appTables application by utilizing jQuery

Is there a way to save the session value in the search box of appTables by using jQuery? <?php $session = \Config\Services::session(); ?> <script type="text/javascript"> $(document).ready(function () { var searc ...

The color of the progress bar shifts according to its value

In my MySQL database, there is a field called progress_profile where I input values ranging from 1 to 100. $progress = $row['progress_profile']; Within the bootstrap-bar code, the following snippet is implemented: <p class="bioheading">P ...

learn the technique I use to incorporate a see-through background in HTML

Is there a way to enclose a specific section of text with a background to improve readability, considering that changing the text color is not the preferred solution due to an existing background image? ...

Having trouble resolving the TemplatesDoesNotExist error even after updating BASE_DIR with the correct path to templates in settings.py?

Issue with Error Message While troubleshooting an error, I encountered an exception value that referenced a file named registration/login.html which I do not have in my templates. Instead, I have a file named sign-in.html. The mention of login.html in the ...

What is the best way to create transparency within an icon's background without affecting the surrounding box?

Is there a way to set the background color of the icon inside the circle without affecting the transparent box around it? Currently, when I use background:white, it changes both the circle and the surrounding box. https://i.sstatic.net/mlV1I.png ...

Morris.js tutorial: Enhancing bar charts with data labels

I have this: https://i.sstatic.net/GXjur.png But I want this instead: https://i.sstatic.net/spcS2.png Does morris.js support this feature? If not, what would be the most effective method to implement it? ...

Issue with vertical navigation bar

Currently working on creating a vertical navigation bar without any styling. It's challenging to figure out how to align the items properly side by side. You can check out the basic functionality at . When clicking on 'Android', I want the g ...

Issue with box shadow appearing incorrectly as element content increases in size while the body has an image background

After applying a box shadow to the header div, I noticed that the box shadow doesn't display properly when the hidden elements within the header are revealed. <div id="header"> <div id="logo"> <a href="#"><img src="logo.png" ...

Why is it possible to apply column width to a div element, but not to a button?

This code functions properly and sets the button to a size 4: <div class="col-xs-4"> <button class="btn btn-block btn-primary">Like</button> </div> However, the following code does not work as expected: <div> <bu ...

Interacting with Django backend via AJAX to trigger Python functions using jQuery/AJAX

Currently, I am developing a small website using Django. Within this project, there are DateTime fields that need to be handled. My intention is to utilize ajax by implementing another button to establish the UTC date while taking into consideration sola ...

Process of converting Ionic application for Android and iOS to APK format

I recently transformed my website into an ionic app, and I've noticed that the app size is almost 15MB. All my JS, HTML, and CSS files are currently stored in the www/app directory, with Bower components located in www/lib. To optimize the size of the ...

Determining the visible dimensions of an iframe

Is there a way to determine the visual size inside an iframe using JavaScript or jQuery? In this scenario, only a portion of the iframe is displayed. The iframe itself has dimensions of 300x300, but it is being limited by a div to 300x100. <div style= ...