The CSS background image doesn't appear on my personal device

I am having trouble using a local image as the background image for a section of my website. Even after entering the image URL and running the project, nothing is appearing. As a beginner in CSS and HTML, I would greatly appreciate any help or advice on how to solve this issue.

Here is the code for the HTML file:

<body>
    <header>
        <h1 class="logo">JN</h1>
        <nav>
            <ul>
                <li><a href="#about">About</a></li>
                <li><a href="#youtube">YouTube</a></li>
                <li><a href="#articles">Articles</a></li>
                <li><a href="#vine">Vine</a></li>
                <li><a href="#social">Social</a></li>
                <li><a href="#podcasts">Podcasts</a></li>
                <li><a href="#share">Share</a></li>
                <li><a href="#more">More</a></li>
            </ul>
        </nav>
        <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8efae6e7fde3efe7e2e7fde8e1fcfcefe0eae1e3fdfafbe8e8fdcee9e3efe7e2a0ede1e3">[email protected]</a>">Email me</a>
    </header>
</body>

Below is the CSS code:

h1.logo {
  visibility: hidden;
  background-image: url(JN-website-logo-Transparent-background.svg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

The path to the CSS file on my computer is:

/Users/justin/Desktop/JN website/JN/public_html/CssAbout.css

The image path on my computer is:

/Users/justin/Desktop/JN website/JN/Image/JN-website-logo-Transparent-background.svg

Answer №1

delete visibility:hidden

h1.logo {
 background-image: url(JN-website-logo-Transparent-background.svg);
 background-repeat: no-repeat;
 background-position: center;
 background-size: contain;
}

Answer №2

Within your CSS code, there are two significant lines that stand out:

  1. visibility: hidden;

Clearly, this line is straightforward in its purpose - it renders the h1 element invisible. Therefore, it is safe to omit this line entirely.

  1. background-image: url(JN-website-logo-Transparent-background.svg);

Regarding this particular line, it's essential to consider the following paths:

The path to the CSS file on my computer is:

/Users/justin/Desktop/JN website/JN/public_html/CssAbout.css

The path to the image on my computer is:

/Users/justin/Desktop/JN website/JN/Image/JN-website-logo-Transparent-background.svg

You have set the background-image to a file named

JN-website-logo-Transparent-background.svg
. However, this file is not located in the same directory as your CSS file. To rectify this issue, you will need to modify the line to: background-image: url('...');, replacing the dots with the correct path to your image file.

Answer №3

Consider eliminating the visibility: hidden; declaration

Alternatively, modify it to visibility: visible;

Answer №4

Consider adjusting the size of the h1 element

h1.logo {
  background-image: url(http://domaingang.com/wp-content/uploads/2012/02/example.png);
  //your image
  //background-image: url(JN-website-logo-Transparent-background.svg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  width:200px;
  height:200px;
}
<body>
    <header>
        <h1 class="logo"></h1>
        <nav>
            <ul>
                <li><a href="#about">About</a></li>
                <li><a href="#youtube">YouTube</a></li>
                <li><a href="#articles">Articles</a></li>
                <li><a href="#vine">Vine</a></li>
                <li><a href="#social">Social</a></li>
                <li><a href="#podcasts">Podcasts</a></li>
                <li><a href="#share">Share</a></li>
                <li><a href="#more">More</a></li>
            </ul>
        </nav>
        <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3c7dbdac0ded2dadfdac0d5dcc1c1d2ddd7dcdec0c7c6d5d5c0f3d4ded2dadf9dd0dcde">[email protected]</a>">Email me</a>
    </header>
</body>

Verify if the image is now visible.

Answer №5

h1.logo {
 background-image: url(website-logo-transparent.png);
 background-repeat: no-repeat;
 background-position: center;
 background-size: contain;

 font-size: 0px;
 line-height: 25px;
}

The combination of font size and line-height properties in the CSS code above ensures that the text within the h1 element remains invisible while still displaying the background image effectively. Adjusting the line-height value is key to maintaining the proper size and appearance of the heading.

Answer №6

You make reference to

...after inputting the URL of the image and launching the project

It appears that your website is operating on a local http test server, indicating that the server utilizes a domain or alias for your website (for example: localhost/JN website or 192.168.xxx.xxx/JN website).

The server adds this before the filename (as in http://localhost/Users/justin/Desktop/JN website/JN/Image/JN-website-logo-Transparent-background.svg) which is not valid. Consider modifying the CSS to

background: url(../Image/JN-website-logo-Transparent-background.svg)
which is a relative path to the image and should be accessible by the server (like localhost/Image/JN-website-logo-Transparent-background.svg).

Also, make sure to delete h1 {visibility: hidden}

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

Determining the class or ID name of an element by assessing the value of a specific attribute

Is it possible to retrieve the class or ID names of all elements with a specific attribute value? For instance, given the code below: <rect class="rect0" x="45" y="0px" width="40px" height="40px" fill="#ff0000" selected="0"></rect> <rect cl ...

What is the most effective way to transfer color values from one div to another?

When recreating a game similar to Mastermind, I encountered a challenge of copying color values from one div to another upon clicking a button. Despite browsing the web, I haven't found a solution for this specific situation. Below is the code I have ...

"Achieving Alignment: Placing a Div Element Inside an H

I am in the process of building a portfolio for freecodecamp, but I am having trouble with centering the button and row div on the page. The row div is necessary because I will be adding more buttons later on, but for now I just need the FCC button. Below ...

Pressing JavaScript buttons to trigger another button

I am looking to develop a script that generates a button which then creates another button. The subsequent button will be assigned an id attribute by incrementing from 1 to infinity. This feature should apply to all buttons (original button and the newly ...

Is it possible for Javascript to fetch a sound from the server once and then duplicate it across n different objects when loaded multiple times?

Incorporating Javascript into my work is crucial. Here's an example: sound = []; for (var i = 0; i < 20; i ++) sound[i] = new Audio("source.wav"); My concern is whether the sound will be retrieved from the server 20 times, or just once. I a ...

Having trouble with the image resizing in Bootstrap 5 on Safari?

I am facing an issue with a website: There are four images under the section "Serviceangebote" that appear as square icons representing circles. I have no trouble viewing them correctly on Windows (Chrome, Firefox, Edge) and Android devices. The images ar ...

My custom class is being ignored by Tailwind CSS within breakpoints

I'm attempting to incorporate some animation on the height property within the md breakpoint, but for some reason Tailwind CSS isn't applying my class. <div className={`h-12 bg-blue flex w-full text-white fixed mt-1 md:bg-white ${scrolling ? ...

Enhanced HTML5 semantic functionality available for all browsers requiring it

There is a tool called HTMLshiv that we are instructed to use with IE9- but it seems that older versions of other browsers do not fully support those tags. Is there a combined conditional statement that can be used for all browsers? If HTMLshiv only work ...

Exploring the capabilities of soup.find() for achieving partial matches

I've been struggling to find an answer to this issue elsewhere, so I'm turning to this code: soup.find(text="Dimensions").find_next().text to extract the text after "Dimensions". The problem arises on the website I'm scraping beca ...

I am looking for a way to distinguish between mandatory and non-mandatory input fields in React

I've encountered an issue with the borders of the text fields in my React project. Here's how I want the text fields to look: https://i.stack.imgur.com/MP6DG.png Currently, the borders appear straight in the browser even though I want them rou ...

Adjusting the spacing between characters in SVG text elements

Take a look at this unique SVG: <svg xmlns="http://www.w3.org/2000/svg"> <defs> <style type="text/css"><![CDATA[ .code { font-family: monospace; white-space: pre; tab-size: 4; } ]]></style> </defs> <text class="cod ...

Determining When to Apply max-height / max-width for Images in CSS

At what point should one consider using max-height or max-width for an image? Is it beneficial if I refrain from mentioning the specific dimensions of the image due to uncertainty? ...

Unable to adjust the width of a table column within a horizontally scrollable container

I am struggling to resize the columns of a large table with 20 headers. Despite trying to place the table inside a div with overflow:auto, I still cannot achieve horizontal scrolling or make the div expand when resizing the columns. A sample code snippet ...

Is it possible to retrieve all PHP classes that share a common word in their names?

Is there a way in PHP to match all classes with the same word? For example: <div class="classeby_class"> <div class="classos-nope"> <div class="row"> <div class="class-show"></d ...

What is the best way to open a new window, such as a music player, and integrate it into a Shopify environment

Currently, within my Shopify store, I am using the following code: <script language="javascript" type="text/javascript"> function popupwindow(url, winName, w, h) { var left = (screen.width/2)-(w/2); var top = (screen.height/2)-(h/2); return wi ...

Changing the hidden input value to the data-id of a selected <a> element

I've set up a form with a dropdown menu and subdropdowns, generated using a foreach loop through a @Model. When I click on one of the options, I want the value of my hidden input field to match the data-id of the clicked item. This is what I have in ...

How can triple nested quotes be utilized within Django templates?

Currently, I am attempting to utilize inline CSS and load an image as a background in a Django template. My goal is to include three quotes, however, I am unsure of the correct way to achieve this. Can anyone provide guidance on how to properly modify the ...

Instructions for adding transitions to an entire page in material-ui while maintaining a fixed AppBar

Is there a way to ensure that the material-ui AppBar remains fixed at the top while being wrapped with page contents in a transition? I want the AppBar to transition (e.g. Zoom or Slide) along with the rest of the page contents. I encountered this issue w ...

HTML - maintain centered text positioning while implementing padding on the left side

Here are the HTML and CSS code snippets I am working with: #page { background-color: #000; color: #fff; height: 360px; width: 360px; min-height: 100%; } #viewport { font-size: 20pt; text-align: center; } .taskTitle { height: 13%; fon ...

Clicking a button in VueJs will trigger the clearing of the displayed text and the subsequent execution of

Hello, I am new to the world of web development and I'm currently learning vue.js. I am working on an app where I input an ID and upon clicking the search button, a method is called. This method utilizes axios to make a request to the controller and ...