The directories for .css and .html files do not overlap, they are in separate locations

mystyle.css file :

table {
    border-collapse: collapse;
}
tr, th, td {
    border: solid 1px #fff
}
td {
    width: 50px;
    padding: 15px
}
th {
    background: #006599;
    color: #fff
}
table.inner tr:nth-child(even) {
    background: #c7d4e5
}
table.inner tr:nth-child(odd) {
    background: #E5E5E5
}
h1 {
    margin-bottom: 0;
    padding: 0.3em 0;
    border-bottom: 1px solid #777;
}
h2 {
    color: #999;
    font-size: 1.2em;
    padding-top: 0.4em;
}
address {
    padding: 0.8em;
    font-size: 0.9em;
}
page {
    background: white;
    display: block;
    margin: 0 auto;
    margin-bottom: 0.5cm;
}
page[size="A4"] {
    width: 21cm;
    height: 29.7cm;
}
page[size="A4"][layout="portrait"] {
    width: 29.7cm;
    height: 21cm;
}
page[size="A3"] {
    width: 29.7cm;
    height: 42cm;
}
page[size="A3"][layout="portrait"] {
    width: 42cm;
    height: 29.7cm;
}
page[size="A5"] {
    width: 14.8cm;
    height: 21cm;
}
page[size="A5"][layout="portrait"] {
    width: 21cm;
    height: 14.8cm;
}
.header, .content {
    padding-right: 30%;
}
.center {
    text-align: center;
}
.border {
    border: 1px solid #777;
}
.border td, .border th {
    border: 1px solid #777;
}
table {
    border-collapse: collapse;
}
table td, table th {
    border-collapse: collapse;
    padding: 4px 8px;
}
@media print {
    body, page {
        margin: 0;
    }
    .djDebug {
        display: none;
    }
}
@media screen {
    html {
        background: #999;
    }
    body {
        margin: 20px 30%;
        padding-top: 3em;
        padding-left: 3em;
    }
}

My .html file

<!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <!--put all your javascript library or style here-->
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="/static/loanwolf/css/mystyle.css">

    <script>
    window.print()
    </script>

</head>
<body>
    {% load i18n %}
    <table>
        <tr>
            <th>
                <center>
                    <h1>Test - {% trans "Customer profile" %}</h1>
                    <center></center>
                </center>
            </th>
        </tr>
        <tr>
            <td>{% trans "Date" %}</td>
            <td>{% now "jS F Y" %}</td>
        </tr>
        ... // Rest of the content truncated for brevity

</body>
</html>

The .html file and .css file are not located in the same directory. The first one is located in

/home/jeremie/Projects/Test-Django/loanwolf/templates/loanwol‌​f/customers
and mystyle.css is located in
/home/jeremie/Projects/Test-Django/loanwolf/static/loanwolf/css
. How could I modify the line
<link rel="stylesheet" type="text/css" href="mystyle.css">
in such a way it works?

Answer №1

{% load static %}    

<!DOCTYPE html>

...

<link rel="stylesheet" type="text/css" href="{% static 'css/mystyle.css' %}">

It is important to ensure that your STATIC settings are configured correctly in order for the above code to work properly. For further information on static files, refer to this link.

Answer №2

To change the link, simply adjust the href attribute to: href="../styles/mystyle.css"

Answer №3

If the file is not located in the same folder, you will need to provide the path to access it. There are two main types of paths - absolute and relative. An absolute path specifies the full path starting from the root directory, while a relative path is based on the location of your HTML file.

To link your stylesheet using its relative path, you can use

<link rel="stylesheet" type="text/css" href="../../../static/loanwolf/css/mystyle.css">
. In this example, the .. signifies the parent folder.

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 it possible to navigate to a different section of a webpage while also jumping to a specific id within that section seamlessly?

I'm trying to create a navbar link that will take me directly to a specific section of a page, but I'm having trouble getting it to work. Here's what I've tried: <a href="home#id" class="nav-link text on-hover"></a> Where ...

Using Javascript to create a radio button group

Is there a way to trigger an alert message when all radio buttons are checked as 'no'? I currently am only able to check each radio button individually. //The method I currently know $('#attraction1').change( function(){ if ($(this ...

Record a message on my command line server (localhost:8000)

def clean_expired_requests(): now = datetime.datetime.now() qs = Request.objects.filter( expires_at__date=now, state__in=[ 'documents', 'validation', 'evaluation', 'signature']) ...

Display or conceal table elements in a loop using jQuery

Currently, I am learning Jquery coding and my current task involves showing or hiding TABLE elements when a SPAN element is clicked. Below you can see the Jquery code that I have tried but unfortunately it is not functioning as expected. This is the HTML ...

Guiding a WordPress Form Submission to a Different Page

I'm currently using WordPress to create a form with the following code: [contact-form][contact-field label='What message would you like to send?' type='textarea' required='1'/]Word Limit: 50 words[contact-field label=&ap ...

Could we incorporate a backwards typewriter animation?

Is there a way to delay this animation for 2 seconds before playing in reverse? I came across this online and made some edits, but I'm still new to this (early stages). Can this be achieved using CSS, HTML, and JavaScript? I plan to use this as an ale ...

What is the best way to create a smooth transition for a bootstrap navbar in chrome, toggling from right to left on

I have successfully modified the bootstrap navbar to toggle from right to left instead of top to bottom using the following code: For HTML- <nav class="navbar navbar-inverse" role="navigation" style="height: 55px; padding-top: 2px; background-color: # ...

Unable to locate the specified CSS file

I've been diving into the world of NativeScript and exploring the tutorials provided at . However, I'm facing an issue with getting the platform specific CSS to work properly. Every time I try to run the code, I encounter the following error mess ...

Tips for saving two text inputs using a JavaScript function into a single .txt file

Currently, I'm developing a webpage where users can input values into two textarea fields. Upon clicking the submit button, the program should trigger a download of both text inputs and store them in a text file. While I have successfully managed to s ...

Troubleshooting a glitch with passing a variable to a PHP script using AJAX

Explanation of the page functionality: When the quiz php page loads, a user can create a score using a function in quiz.js. This score is then stored in a variable score within quiz.js Once the score is generated, the user must click a button to move on ...

JavaScript interactive chart utilizing a table format

My goal is to create an engaging chart in the form of a table that informs users whether a service was operational or not on specific days of the month in a particular year. When a user clicks on a field, it should open a new URL with more detailed informa ...

Aligning content in CSS for cross-browser compatibility with Internet Explorer and Chrome

My CSS grid has grid items that can easily be centered in Chrome by using the justify-items:center property, creating a magical effect. However, this solution does not work in Internet Explorer as the items remain stuck to the left side. For reference: ht ...

Get rid of the border when the display property is changed to none

I am facing a challenge with removing a border when the display property is set to none, despite it being a seemingly simple task. My understanding has always been that setting the display property to none removes an element from the HTML flow. However, i ...

Switching charset/encoding on load() using jQuery

Query: How can the encoding of a text file being loaded through jQuery's load() function be adjusted? I previously had a single page, index.html, where I consolidated all my css, js, and html content. Now, I aim to separate the header section from th ...

Emphasize the most recent file during the document upload process and ensure the scroll bar moves accordingly to the document

I am currently working on a feature where the scroll bar should move to the newly uploaded document in a list of documents. When I upload a new document, I want the scroll bar to automatically move to that document. Currently, the highlighting changes to t ...

Steps to analyzing information post a query

I am currently working on a form that allows users to input data. Once the data is submitted, I want to display a success message, process the information, and then store it in the database. While everything is functional, I have encountered an issue wher ...

Tips for preventing HTML ID clashes while integrating with the Document Object Model of external websites

When incorporating additional HTML elements into a webpage using Javascript or jQuery, along with external CSS declarations, it is important to avoid conflicts with existing IDs and class names already present on the page. This could lead to issues if ther ...

How to create a faded effect on a background image within a bootstrap carousel

Can anyone help me figure out how to make my images darker in order to enhance the readability of the text on them? I am using a bootstrap carousel theme and struggling to achieve the desired darkness. Opacity adjustments are affecting the transparency of ...

Updating and showing a variable in a PHP file using JavaScript within an HTML webpage

My goal is to establish a variable in a PHP file on my server named "likes." Subsequently, I wish to incorporate a like button on my HTML webpage that, when clicked, will utilize JavaScript to modify the "likes" variable in the PHP file and increase it by ...

How can I switch between columns in a dual-column layout?

In my latest project, I utilized CSS Flexbox to create a sophisticated two-column layout that allows toggling each column independently. While this functionality is exactly what I need, I can't help but feel that my current method is somewhat cumberso ...