What is preventing my CSS from being applied to elements other than the body, despite using block content?

I'm trying to customize the style of my webpage body, but it's also affecting my navbar from the base.html file. Can anyone help me understand why this is happening and how I can isolate the styling to just apply only to the <body> contents?

messages.html

{% extends "dating_app/base.html" %}

{% load bootstrap4 %}

{% load static %}


<!DOCTYPE html>
<html>

<head>
...

 

base.html

{% load bootstrap4 %}
{% load static %}
...


    <!-- Navigation -->
     ...


<footer>
<div class="container-fluid padding">
<div class="row text-center">
...
   
     
  </footer>
    <!-- Bootstrap core JavaScript
      ================================================== -->


</body>
</html>
  

Answer №1

Let's make corrections to base.html

{% load bootstrap4 %}
{% load static %}

{% load unread_messages_counter %}

<!-- The Navbar is located in this file -->


<!doctype html>
<html lang="en">
<head>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>


    {% block head %}
    <title>Base</title>
    {% endblock %}

    <link rel="stylesheet"  href="{% static 'css/style.css' %}"/>
    <link rel="stylesheet"  href="{% static  'css/notification.css' %}" type="text/css" class = "notification"/>
    <style>
    <!-- Add this tag -->
    {% block styles %}

    {% endblock %}
    </style>
</head>
<body>
    <!-- Navigation -->
      <nav class="navbar navbar-custom navbar-expand-md">
      <div class="container-fluid">
        <a class= 'navbar-brand'  href="{% url 'dating_app:home' %}"><img src="{% static 'images/cupids_corner_logo.jpg' %}"><h5 style="color:red"></h5> </a>
        <button class= "navbar-toggler" type="button" data-toggle="collapse" 
        data-target="#navbarResponsive">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div  class="collapse navbar-collapse"  >
          <ul class ="navbar-nav ml-auto" >


            {% if user.is_authenticated %}


                {% unread_messages request.user as user_unread_messages %}
                {% if user_unread_messages > 0 %}


                    <li class="nav-item"  >
                        <a class=  "notification" style="color:brown" href... continue
 

Let's move on the messages.html:

{% extends "dating_app/base.html" %}

{% load bootstrap4 %}

{% load static %}

{% block head %}
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
{% endblock %}

{% block styles %}
body {
  margin: 0 auto;
  max-width: 800px;
  padding: 0 20px;
}

.container {
  border: 2px solid #dedede;
  background-color: #f1f1f1;
  border-radius: 5px;
  padding: 10px;
  margin: 10px 0;
}

.darker {
  border-color: #ccc;
  background-color: #ddd;
}

.container::after {
  content: "";
  clear: both;
  display: table;
}

.container img {
  float: left;
  max-width: 60px;
  width: 100%;
  margin-right: 20px;
  border-radius: 50%;
}

.container img.right {
  float: right;
  margin-left: 20px;
  margin-right:0;
}

.time-right {
  float: right;
  color: #aaa;
}

.time-left {
  float: left;
  color: #999;
}
{% endblock %}

{% block content %}

    <a href="{% url 'dating_app:message' other_user.id %}">Start messaging!</a>

    <h2>Chat Messages</h2>
    {% for message in messages %}

        {% if message.sender_id == request.user.id %}
        <div class="container">
            <img src="{{  profile.photo.url  }}" alt="Avatar"... continue
 

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

Provide the option to download a CSV file that has been created by a Python script

Is it possible to create a Python script that runs when a button is clicked through ajax? The script should generate a CSV file and allow users to download it. What steps can be taken to make this possible? ...

Struggling with configuring a personalized version of Bootstrap 4 in Sass

I am currently in the process of creating a custom version of Bootstrap 4. One of the main changes I want to make is switching the default color ("primary") from Bootstrap Blue to something different. Initially, I made the edits directly to the Bootstrap ...

Using @Input to pass data from a parent component to a

Looking to modularize the form code into a separate component for reusability? Consider using @Input and referencing it in the HTML to pass values to the post method. Here's how you can achieve this: Previously, everything worked smoothly when all th ...

How to retrieve the button value in HTML

One of the HTML components I am working with is a button that looks like this: <button>Add to cart</button> My goal is to retrieve the text within the button, which in this case is "Add to cart." To achieve this, I need to extract this value ...

Issue with cutting of rotating pseudo element

Trying to rotate a pseudo element with a background-image is posing a challenge. The background, positioned at the center of the main element for visual effect, ends up being cut off when rotated. An illustrative example has been created using random imag ...

Scroll the table automatically when the currently selected row is the second-to-last row

Having trouble with a scrolling table issue. https://i.sstatic.net/PFyN3.png Upon page load, the first row (ROW 1) is automatically selected and highlighted. Clicking the next button selects and highlights the subsequent rows. However, once ROW >= 8 (e ...

"Django's data generation for testing is moving at a disappointingly slow

Using Django 1.8 and Postgres 8.4.20, I am currently working on preparing performance test data in the database. My goal is to generate 100,000 Django Users along with various other model instances. Below is the code snippet I am using: for n in range(100 ...

Adjust the height of the tabs bar in the Guake terminal

Is there a way to reduce the height of the tabs bar in the Guake terminal? I found a solution for GNOME terminal on this post, where they mentioned editing ~/.config/gtk-3.0/gtk.css. Is there a similar method for achieving this in Guake terminal? ...

Tips for creating responsive emails

Yesterday, I posted about my email newsletter and received some helpful feedback on creating a good structure. I implemented the suggestions provided into my newsletter and also added media query code to make layout adjustments for supported email clients. ...

Utilizing nprogress.Js for a Dynamic Progress Bar

I'm trying to create a progress bar similar to the one on YouTube using the nprogress.js plugin. However, I want the progress to start from the middle of the page, like this: start | --------------------------------------------> | end Instead of: ...

The accuracy of getBoundingClientRect in calculating the width of table cells (td)

Currently, I am tackling a feature that necessitates me to specify the CSS width in pixels for each td element of a table upon clicking a button. My approach involves using getBoundingClientRect to compute the td width and retrieving the value in pixels (e ...

Ensuring various conditions with ngIf

I've created a toggle function that updates the text of a link, but I'm struggling to handle multiple conditions. For example, *ngIf="condition1 or condition2". Below is an excerpt from my code: <a routerLink="/ads" class="tip" (click)="togg ...

Inspecting element value on a website

On a marketplace website, I extracted the attribute (capacity_gold) from a table. Since the values are dynamic and constantly changing, I aim to develop a basic script that will notify me when the attribute value exceeds 100. The current value of the attr ...

Close button situated at the top-right corner overlapped by HTML/CSS styling

Currently attempting to position a button overlapping and extending outside of its parent div, much like the illustration provided. However, my current efforts result in the button being contained within the parent DIV. The visual reference below showcases ...

The JavaScript code in the HTML files is not functioning as expected

Upon form submission in my program, the form action directs to xyz.php. Within xyz.php, I simply use INCLUDE("abc.html") to redirect to another HTML page. The abc.html page contains HTML tags and JavaScript code, but after the form submission, the page red ...

The function is not recognized in C# programming language

Whenever I try to trigger functions by clicking buttons, nothing seems to happen and an error message appears in the console. Uncaught ReferenceError: AddressInputSet is not defined at HTMLButtonElement.onclick I'm new to this and could use ...

Arrange a stationary child in relation to the grandparent element

I created a small window within a browser window, containing an even smaller window with auto-scrolling text. However, I need some text in the smaller window to remain static and not scroll. Therefore, I used position_fixed which is absolutely related to ...

Error: The object of 'set' type does not have the 'decode' attribute

For my school project, I decided to dive into Django and work on a chat project using a websocket server. Oddly enough, I encountered an error upon reloading the app, even though I'm not using the decode() function anywhere in my code. My setup involv ...

What could be causing the malfunction of this Bootstrap button dropdown?

Initially, I attempted using regular HTML for the dropdown button but encountered issues. As a result, I switched to jsfiddle to troubleshoot. Despite my efforts, the dropdown feature still refused to work. If you'd like to take a closer look, here&a ...

What is the method for adjusting the position of materialize CSS select options?

https://i.stack.imgur.com/b9p9T.png One issue arises when I open the Materialize CSS select, as the options end up covering the input. Ideally, I prefer the options to appear underneath the input. <div class="input-field "> ...