Including CSS in an HTML file does not function properly

I've been attempting to import a CSS file into an HTML document, but for some reason it's not working. I have also tried linking the path directly, but that hasn't worked either.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Lesson</title>
<meta charset="utf-8">
<style rel="stylesheet">
@import url("U5.css");
</style>
</head>
<body>

<script src="assets/script/U5.js" ></script>

</body>

However, it seems like using "http:....." as a format is successful;

  • U5-LättJS
  • href="http://127.0.0.1:54149/assets/pages/U5-JS.html"
    

    Is there a way to convert the path to an http format so it will work? Thank you.

    Click here for the validated code picture

    Answer №1

    To link your CSS file in the same directory, use this code:

    <link rel="stylesheet" type="text/css" href="./U5.css">
    

    If your HTML file is at the root, you can use this code:

    <link rel="stylesheet" type="text/css" href="/assets/pages/U5.css">
    

    For more information on linking external style sheets, visit https://www.w3schools.com/Tags/tag_link.asp

    Answer №3

    Hooray! I've finally figured out how to achieve that. By copying the HTML path and using it as a style path, everything fell into place. As an illustration, for HTML:

    href="http://127.0.0.1:54149/assets/pages/U5-JS.html"
    

    After making the necessary adjustments, this is what the style tag looks like:

    href=''http://127.0.0.1:54149/assets/style/U5.css'' 
    

    The solution works perfectly now. The mystery of what went wrong remains unsolved. Nevertheless, immense gratitude to everyone who contributed their efforts. Thank you!

    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

    Using a combination of CSS selector, several attributes, and the OR operator

    Can you assist me with CSS selectors? Let's say we have a style HTML tag: <style type="text/css"> [...selector...] {color:red;} </style> I want to create a selector with multiple attributes and logical operators, but I am uncertain about ...

    I need assistance setting up a Facebook page feed using Angular.js. I want to display the posts in a list of cards and include a fullscreen image gallery. Is

    Hey there! I'm in the process of developing an app that pulls Facebook page posts and showcases them with custom CSS. The app is functioning smoothly with two controllers, DashCtrl and MainCtrl, each working fine on its own. However, when trying to tr ...

    What is the best way to adjust the position of the previous and next buttons on a Bootstrap 5 carousel?

    I am having trouble figuring out how to properly position the previous and next buttons in a bootstrap5 carousel. The original code I used as a template was for a carousel that displayed 4 images at once, but I changed it to display 3 images at once. I a ...

    Altering the placement of a single element from floating to fixed positioning in CSS

    Currently in the process of designing a basic website, I am looking to modify the behavior of the navigation bar on the left-hand side. I want it to remain fixed in its position so that users can scroll through the page without losing sight of it. My main ...

    How can I select a specific value within an Autocomplete bar by clicking on it in the div ul li strong

    I have a multitude of li tags nested under both div and ul. Each li tag contains a strong element: <div style="width:380px" id="autoComplete" class="suggest fl"> <div class="sWrap"> <div class="iconWrap"> <span ...

    How to modify the color of a div element with jQuery?

    I need some help changing the color of a div with 'jQuery', but I am not sure how to do it. Below is the code I have been trying: function updateDivColor() { $('#OutlineX1').css("color","blue"); } ...

    Exploring the art of JSON interpretation within Highcharts

    Below is an example snippet that utilizes static data: Highcharts.chart("container", { title: { text: "Highcharts pie chart" }, xAxis: { categories: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Ju ...

    Fade in images using jQuery

    I am having issues with fading in and out images using jQuery, it doesn't seem to be working as expected. I think there might be something crucial that I am missing. Take a look at the script below: var count = 1; setInterval(function() { ...

    Positioning Elements with CSS Relative and Absolute Placement

    I am relatively new to the world of web design and currently grappling with the concept of positioning in CSS. I have a basic understanding of relative and absolute positioning for elements. In the code snippet below, there is a <div> that acts as th ...

    Error message: "An issue occurred with the Bootstrap Modal in

    I've designed an AngularJS app like so: <!DOCTYPE html> <html ng-app="StudentProgram"> <head> <title>Manage Student Programs</title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2. ...

    Having trouble locating and scrolling through elements while webscraping with Python Selenium, encountering the 'cannot focus element' error

    I have been trying to extract ticket information from the VividSeats website. The URL I am working with is '' My tools of choice are Selenium and Python. I managed to navigate to the page using Chrome WebDriver and interact with the pop-up tha ...

    Display or conceal a <div> segment based on the drop down selection made

    A dropdown menu controls the visibility of certain div elements based on the selection made. While this functionality is working for one dropdown, it's not working for another even though the code is very similar. I've tried various solutions but ...

    The clash of interests between jQuery and Bootstrap

    I'm facing a problem with conflicting jQuery and Bootstrap files in my header.php code. Whenever I include the jQuery file before the bootstrap.js file, it causes issues with the tabs on my website where clicking on them does not navigate me to the co ...

    Switch the background color when a radio button is chosen

    For my quiz on test practice with an array of questions, each question includes five radio buttons, but only one is correct. Initially, all five options have a gray background. Upon selecting a wrong option, it changes to red. If another incorrect option i ...

    Change the color of unordered list items only at the same level

    Hey there! I'm working with this HTML code: <ul id="nav" class="nav-1"> <li><a href="#">Loans</a></li> <li><a href="#">Bancassurance</a> <ul class="nav-2"> <li><a href="#"&g ...

    Ways to determine if content is visible within a div

    My website contains a script that brings in content from an ad network and displays it within a div element. Unfortunately, this particular ad network only fills ads 80% of the time, leaving the remaining 20% of the time without any ads to display. This la ...

    Enhancing the functionality of angular-messages is impacting the overall design of

    Displaying here is the current state of my login form: However, subsequent to upgrading angular-message to version 1.4 and higher, the layout transforms into this: Sharing my source code for reference: <ion-view view-title="Login"> <ion-hea ...

    Color-matching cells must be positioned in the same column within the gridbox consecutively

    In my current project, I am dealing with a large number of sections. Each section contains one or two rows with columns ranging from 2 to 15, all of equal width. The cells of the same color are placed in the same column, and the layout looks like this: To ...

    Rotating through elements in timed intervals

    After exploring various examples of how to show/hide divs with a JavaScript timeout, I am still unable to resolve my specific issue. I currently have six divs that I want to cycle through sequentially every 10 seconds, starting with div #one. Although my ...

    Matching utility types and themes in Tailwind CSS

    I encountered an issue while trying to implement the Tailwind plugin in my project. It seems that a TypeScript error has occurred. I'm curious about the data types of matchUtilities and themes. Can someone provide some insight? const plugin = require( ...