Exploring the integration of HTML and CSS within the Django framework

Trying to implement a star rating in a specific HTML file

The file I am working on is called book_detail.html

{% extends "base.html" %}

{% load static %}

{% block title %}
Block Detail Page
{% endblock title %}

{% block sidenav %}
{% for item in item_list %}
<li>
    <a href="{{ item.link }}"> {{ item.item }} </a>
</li>
{% endfor  %}
{% endblock sidenav  %}

{% block content %}

<h1 align="center"> Book Detail </h1>
<table align="center" border="2" width="400">
    <tr>
        <td>
            {{ book.name }}
        </td>
    </tr>
    <tr>
        <td>
            <img src="{% static book.pic_path %}" width="100">
        </td>
    </tr>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <tr>
        <td>
            {{ book.username }}
            <div id="full-stars-example">
                <div class="rating-group">
                    <input class="rating__input rating__input--none" name="rating" id="rating-none" value="0"
                           type="radio">
                    <label aria-label="No rating" class="rating__label" for="rating-none"><i
                            class="rating__icon rating__icon--none fa fa-ban"></i></label>
                    <label aria-label="1 star" class="rating__label" for="rating-1"><i
                            class="rating__icon rating__icon--star fa fa-star"></i></label>
                    <input class="rating__input" name="rating" id="rating-1" value="1" type="radio">
                    <label aria-label="2 stars" class="rating__label" for="rating-2"><i
                            class="rating__icon rating__icon--star fa fa-star"></i></label>
                    <input class="rating__input" name="rating" id="rating-2" value="2" type="radio">
                    <label aria-label="3 stars" class="rating__label" for="rating-3"><i
                            class="rating__icon rating__icon--star fa fa-star"></i></label>
                    <input class="rating__input" name="rating" id="rating-3" value="3" type="radio" checked>
                    <label aria-label="4 stars" class="rating__label" for="rating-4"><i
                            class="rating__icon rating__icon--star fa fa-star"></i></label>
                    <input class="rating__input" name="rating" id="rating-4" value="4" type="radio">
                    <label aria-label="5 stars" class="rating__label" for="rating-5"><i
                            class="rating__icon rating__icon--star fa fa-star"></i></label>
                    <input class="rating__input" name="rating" id="rating-5" value="5" type="radio">
                </div>
            </div>
        </td>
    </tr>
</table>
{% endblock content %}

This is the CSS that needs to be connected with the star rating in my HTML, found in main.css

@charset "utf-8";

#header {
    border-style: none;
    width: 800px;
    height: auto;
}

#wrapper {
    margin-top: 8px;
    margin-left: auto;
    margin-right: auto;
    background-color: #FFFFFF;
    width: 800px;
}

#leftsidebar {
    width: 180px;
    height: 350px;
    float: left;
}

#nav li {
    padding-top: 10px;
    padding-bottom: 10px;
    list-style-type: none;
    border-bottom: thin solid #5F5F5F;
    color: #4C4C4C
    left: 8px;
    list-style-position: inside;
    margin-left: -10px;
}


#main{
    width: 560px;
    float: left;
    margin-left: 20px;
    margin-right: 10px;
    padding-right:10px;
}

#footer{
    text-align: center;
    margin-top: 5px;
    padding-top: 10px;
    padding-bottom: 10px;
    border-top: thin solid #BBBBBB;
    clear: both;
    color: #969696;
}
#full-stars-example {
 /* use display:inline-flex to prevent whitespace issues. alternatively, you can put all the children of .rating-group on a single line */
  .rating-group {
    display: inline-flex;
  }

  /* make hover effect work properly in IE */
  .rating__icon {
    pointer-events: none;
  }

  /* hide radio inputs */
  .rating__input {
   position: absolute !important;
   left: -9999px !important;
  }

  /* set icon padding and size */
  .rating__label {
    cursor: pointer;
    padding: 0 0.1em;
    font-size: 2rem;
  }

  /* set default star color */
  .rating__icon--star {
    color: orange;
  }

  /* set color of none icon when unchecked */
  .rating__icon--none {
    color: #eee;
  }

  /* if none icon is checked, make it red */
  .rating__input--none:checked + .rating__label .rating__icon--none {
    color: red;
  }

  /* if any input is checked, make its following siblings grey */
  .rating__input:checked ~ .rating__label .rating__icon--star {
    color: #ddd;
  }

  /* make all stars orange on rating group hover */
  .rating-group:hover .rating__label .rating__icon--star {
    color: orange;
  }

  /* make hovered input's following siblings grey on hover */
  .rating__input:hover ~ .rating__label .rating__icon--star {
    color: #ddd;
  }

  /* make none icon grey on rating group hover */
  .rating-group:hover .rating__input--none:not(:hover) + .rating__label .rating__icon--none {
     color: #eee;
  }

  /* make none icon red on hover */
  .rating__input--none:hover + .rating__label .rating__icon--none {
    color: red;
  }
}

Encountering difficulty connecting the star rating section in the HTML with the corresponding CSS file named main.css.

Answer №1

Start by updating the base.html file in your project:

{% block head %}{% endblock head %}

Next, go to book_detail.html and include a reference to your CSS file:

{% block head %}
    <link rel="stylesheet" type="text/css" href="{% static 'foldername/styles.css' %}">
{% endblock %}

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

Is there a way to send HTML element values to a MySQL Database in Django using Ajax without utilizing a form?

As a Django newcomer, I am currently encountering an issue with posting HTML tag data into the database. I have implemented a "PICK CASE" button that, when clicked, should pass the user_id (hidden in an HTML tag with display:none) and case_id from the tag ...

Guide on creating a div container that spans the full width of the HTML page with a horizontal scrollbar

I'm facing an issue where the div container is not extending over the entire HTML page with a horizontal scroll bar. Here's a visual representation of my problem: Image Despite using MathJax to display math formulas, the div container does not ...

How to make text transition between colors using CSS or jQuery

I'm looking to make a text blink with alternating colors: For instance: blinking a text with white, green, white, green, white, green I am open to either using jQuery or CSS. ...

CSS file not loading in an ExpressJS application

I'm facing an issue with my ExpressJS web app where only the HTML files are loading but the CSS rules are not being applied. I have linked the HTML file with the CSS file and also included express.static(path.join(__dirname, 'css')) in my ap ...

Adding clickable padding to a Draft.js editor can enhance the user experience and make the editing process

Is there a way to apply padding to the Draft.js Editor so that clicking on the padding area selects the Editor? If I add padding directly to the container div of the Editor, the padding displays properly but clicking on it does not enable writing in the E ...

Incorporating Bootstrap into a fresh project

I'm completely new to the world of development, so I'll do my best to phrase this question correctly! Last month, I successfully created my first web application using RoR and Bootstrap for some visual enhancements. Currently, I am working on a ...

Increase the jQuery level and utilize the .find() method

Currently, I am delving into the realm of jquery and facing a minor hiccup with selectors. Below is the structure of my DOM: <li> <header class="title"> <span>Text</span> <a href="#work-1">My trigger</a> ...

The simple method for incorporating line feed in <s:textarea>

Hey there, I'm currently utilizing struts 2 UI and I seek a means to restrict the number of characters in each row to only 16. Additionally, I want to impose a maximum length limit of 32 characters. Despite my attempts using the 'row' and &a ...

The 'User' object does not contain the attribute 'get_affected_users' when dealing with foreign key relations

I understand the error and I have an idea of why it's happening. However, I'm not sure how to resolve it and reach my objective. Let me explain what I'm trying to accomplish. I want users who have posted something to receive a notification ...

The background image does not appear on the animated div until the browser window is resized

Encountering an unusual problem - I have styled a div element using CSS to be initially hidden: .thediv { width: 100%; height: 87%; position: fixed; overflow: hidden; background-image: url(pics/FrameWithBG1280.png); background-attachment: fixe ...

Transforming the color of a globe from black to white with gio js

After searching for a solution to change the color of a Three.js globe, I came across a link that didn't work as expected: Change the color of a Three.js globe. My goal is to change the globe color from black to white using . I attempted to use the f ...

merge two structures to create a unified entity

I have been searching in vain, can you please advise me on how to combine these two simple forms into one? I want it to be like a box with a select option and a button. The challenge for me is merging the two different actions, ".asp", into one script fo ...

Changing my PHP contact form from method GET to POST is causing it to malfunction

Feel free to check out my contact form on benlevywebdesign.com, located at the bottom of the page. <form id="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="text/plain" method="get"> <fieldset> ...

Is it possible to disable a function by clicking on it?

I currently have a website that is utilizing the following plugin: This plugin enables an image to be zoomed in and out through CSS transforms, with default controls for zooming in and out. My goal is to incorporate a reset button that returns the image ...

Tips for swapping out a new line character in JavaScript

Hello! I'm currently facing a challenge with some code. I have a function designed to replace specific HTML character values, such as tabs or new lines. However, it's not functioning as expected. var replaceHTMLCharacters = function(text){ tex ...

angular2 ngFor is not functioning properly

I'm having an issue where I cannot get textboxes to appear whenever a user clicks a button. I am attempting to achieve this using ngFor, but for some reason, the ngFor is not iterating as expected. Even after trying to change the array reference with ...

css Apply styles to form controls only if they are not empty

Utilizing an angularjs form, I have customized the following example to fit my code: .my-5 { margin:100px; } .form-group { position: relative; margin-bottom: 1.5rem; } .form-control-placeholder { position: a ...

Encountering a JSONDecodeError when sending a python dictionary via AJAX post

I have encountered an issue when passing a Python dictionary to a template and then using $.post to send it to a Django view. When I attempt to json.loads it in the view, I am getting a JSONDecodeError. Does anyone know how I can resolve this? //1. vars t ...

Tips for transferring information to an input field's value

There's an input box with an empty value that needs to be filled with data. <input type="text" value="" class="box"> $('.skills-tags').on('click', function(){ var value = $(".skills-tags").val(); $('.label-pr ...

JavaScript makes it simple to display student names based on their ID numbers

Here is my JavaScript code: <script language="Javascript"> var data = { 7: "Jack Black", 8: "John Smith" }; var id = document.getElementById("id"), emp = document.getElementById("name"); id.addEventListener("keyup", function() { emp.value ...