Local drive fonts fail to function with unique custom fonts

As I explore CSS, I have created the code below to utilize a Google font that is saved on my local hard drive. The HTML file works when it's placed in the font folder, but fails to work in a different directory. It's worth mentioning that I am not using a server; I simply double-click the file after moving it to another folder.

    <!doctype html>
    <html lang="en">


        <head>

            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">


            <title>Custom Fonts</title>

            <style>
                @font-face {
                font-family: 'Abel-regular';
                src: url('file://G:/JavaPrgsJGD/fonts/Google-fonts/Abel/Abel-regular.ttf');
                font-weight: normal;
                font-style: normal;
                }       
            </style>  

            <style type="text/css">

                .ngs-h3 {font-family: 'Abel-regular'; font-size: 30px; color: green;}
                .ngs-p  {font-family: 'Abel-regular'; font-size: 20px; color: blue;}

            </style>

            <script>

            </script>  

        </head>


        <body>

            <h3 class="ngs-h3">Technical assessment of a movie</h3>

            <p class="ngs-p">
                Many people see the movies and immediately after completion of the show, when asked by news channels,
                they simply brush aside the movie saying, "It's a bogus movie" without realizing that what goes in for
                bringing a movie to a cinema theatre for viewers, but of course, they have spent money and time to 
                watch a movie, they at least deserve a free opinion.
            </p>

            <p class="ngs-p">
                However, this forum is not about personal likes and dislikes of down-to-earth movie-goer.  This forum
                is for students who are pursuing their technical studies in film industry.  Therefore, let us concentrate
                on technical aspects of a movie.
            </p>

        </body>


    </html>

Could you help me figure out where I'm going wrong? I'd appreciate some guidance on how to deal with local files both with and without a server. Thank you. NG SHAIKH.

Answer №1

In my opinion, it is highly advisable to avoid using absolute file paths when dealing with front-end web technologies such as CSS. One alternative could be organizing the font in a ./font directory and utilizing an absolute path, or opting for the CDN offered by

@font-face {
    font-family: 'Abel-regular';
    src: url('./fonts/Abel-regular.ttf');
    font-weight: normal;
    font-style: normal;
} 

// or

@import url('https://fonts.googleapis.com/css?family=Abel');

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

Unique and responsive grid styling with CSS

Is it possible to create a responsive grid like the one shown in the image below? I attempted to use absolute positioning for all blocks, but I'm having trouble making it responsive... I should note that the styling will be generated dynamically usi ...

Styling web pages with CSS and utilizing ASP.NET controls

It has come to my attention that when trying to add the 'style' attribute to an asp:TextBox control, or when trying to use a css class to apply a style, it does not seem to work. I find that I have to explicitly set the attribute like this: < ...

When the height of a sibling element restricts the inner content and scroll bar due to the parent element's height being defined in vh

I'm currently working on creating a sidebar that occupies a fixed percentage of the viewport. Inside this sidebar, I want to have an element that remains fixed at the top while allowing the rest of the content to scroll if it exceeds the height of the ...

Creating two horizontal flex containers with an input box that is responsive can be achieved by setting the display property

I need some assistance with a layout issue I am facing. Currently, I have two flex containers in a row - one set to flex-start and the other to flex-end. Both of these containers are within a wrapping div that is also set to flex. When the width of the wi ...

Attempting to dynamically assign a nickname to a CSS element selector during runtime

I have been attempting to adjust the position of a font awesome icon within an input field dynamically. My goal was to have the style calculated at runtime, similar to how I've handled other stylesheet elements in the past. However, I am facing diffic ...

Tips on preventing empty values in a textbox

$(document).on("click", "label.radeem-textbox", function () { var content = $(".mytxt").text(); $(".radeem-textbox").replaceWith("<input class='radeem-textbox redeem-textbox'/>"); $(".radeem-textbox").val(content); r ...

Tips for styling links in Nuxt/Vue based on specific conditions

Struggling with conditional styling in my Nuxt app. I want to change the background color of the active link based on the current page. Using .nuxt-link-exact-active works for styling the active link, but how can I customize it for each page? The links ar ...

Experience the smooth transition effects of sliding down the login box when hovering over an image or div

Is there a way to switch the hover js transition effect to a different transition type like fadeIn, fadeOut, or simple transitions? Check out this link for more details. Here is an example of the HTML code: <img id="login-trigger" src="http://www.join ...

Unlock the power of overlay masks with just CSS and JavaScript on any webpage

After experimenting with different types of masks, I wanted to be able to dynamically create a CSS class and apply it after the DOM had loaded in order to achieve an overlay mask effect. However, my initial attempt was unsuccessful: var style = document.c ...

Struggling to adjust the width of a DIV based on browser size and content with CSS

I'm working with a div that contains several 210x210 pixel images, and I want to adjust its margin from the left side. The goal is for the right side of the div to be just a few pixels away from the images, which will have their own margin set. Strang ...

Align the bottom borders to the lowest content on each line

I am working on designing my homepage using HTML, CSS, JSP, and JavaScript, focusing on the sale of musical instruments and facilitating communication among users. Right now, I am in the process of creating a site-map for my menu configuration chart using ...

Tips for displaying website preloader just once

I recently added a preloader to my website, but I'm having trouble getting it to only play once per visit. Ideally, I want the animation to show up when the site is opened in a new tab or browser window, but not when navigating through the domain by c ...

When the button is clicked, remove the border-bottom

Looking for help with CSS to hide the border-bottom of a button when clicked? I've attached an image for reference. Any suggestions or solutions would be greatly appreciated! View attached imageView attached image I've tried using active, focus ...

The justify-content: space-between command functions properly for the last two products, but is not working as expected for one of the products

I have three products displayed with images and descriptions side by side. I used justify-content: space-between to create spacing between them, which seems to work for the last two products but not the first one, which is very annoying. Even after trying ...

Why doesn't "align-self: flex-end" relocate the game board to the bottom of the screen?

Hey there, I am currently working on developing a Connect 4 game and have decided to use a table for the board. To position the board properly, I am utilizing flexbox. Although I have specified align-items as 'flex-end' in order to bring it to th ...

What is the best way to create a hyperlink with two distinct inputs using ajax?

Including "Form A" and "Form B" on a single page allows users to search for and display movie information simultaneously. Since these forms utilize ajax, the page does not require reloading when choosing a new Movie A or B. However, due to ajax's limi ...

Some divs are not inheriting class properties as expected

I am currently working on a footer section that consists of 4 div elements, each with a shared class. Oddly enough, the first div is extending its width more than expected. The other 3 div elements are adjusting their width based on the content within them ...

Tips for utilizing bootstrap.css to position a web design form in the center of the page and place the copyright at the bottom

I have spent several hours trying to figure out how to achieve this, but still haven't found the solution. I have a form that I believe doesn't look very good: https://i.sstatic.net/t1MRd.png So, I attempted to center the form on the page and ...

How to Retrieve the Width of a Div Element in Jquery with Overflow Hidden

Is there a way to determine the width of a div that is inside another div with "overflow: hidden;"? I attempted setting overflow to auto and then using $("#divselector").width(), but it seems to always provide the width of the parent div! For example: H ...

Arranging elements in a row and column to ensure proper alignment

https://i.stack.imgur.com/LMsTg.png I'm having trouble aligning the UI elements in my Bootstrap 5 project. I can't seem to pinpoint the issue despite trying various solutions. Here's the code snippet: <div class="container"> ...