How come my image isn't moving from my folders to my stylesheet for a DIV element?

My goal is to replicate a webpage template as a way to improve my understanding of HTML/CSS. I am attempting to use an image as the background for a DIV in my document, but for some reason, it's not appearing. Please keep in mind that I am still new to coding.

As a test, I tried using a random stock photo URL from Google and that worked. This makes me wonder if the issue lies with the location of the actual image file (it's in the same folder as the document) or if there is another conflict in my code affecting the display of the image. I'm uncertain at this point.

HTML file:

<html>
  <head>
    <title>conquer</title>
    <link rel="stylesheet" type="text/css" href="conquer.css" />
  </head>
  <body>

    <div class="navbar">
        <a href="">Homepage</a>
        <a href="">About Us</a>
        <a href="">Services</a> 
        <a href="">Contact</a>
        <a href="">External</a>
    </div>

    <div class="topbanner"></div>

  </body>
</html>

CSS file:


body {
    background-color: #fff;
    margin: 0;
}

/** Navigation Bar **/

.navbar {
    background-color: #383E4C;
    height: 100px;
    width: 100%;
    position: fixed;
    text-align: center;
    margin-top: 0px;
}

.navbar a {
    color: #F6F6F7;
    text-decoration: none;
    font-size: 22px;
    font-family: "Helvetica", sans-serif;
    border: 1px solid #646D7C;
    padding: 15px;
    margin-top: 20px;
    margin-right: 20px;
    display:inline-block;
}

.navbar a:hover {
    background-color: #49505F;
}

/** Top Banner **/

.topbanner {
    height: 500px;
    width: 300px;
    background-image: url('/city.jpg');
    background-repeat: no-repeat;
}

The aim was to have the image displayed within the DIV, but when checking the console elements, all I see is a large invisible block.

Answer №1

When specifying paths, the forward slash / at the beginning indicates that the browser should navigate to the ROOT directory.

To make the necessary adjustment, follow these steps:

background-image: url('/city.jpg');

replace it with:

background-image: url('city.jpg');

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

Activate the clicked tab in the Bootstrap navbar when selected

I have gone through similar posts, but I am unable to get mine to work. My goal is to activate the clicked tab. Here is what my bootstrap navbar looks like in HTML: <div class="navbar navbar-default" role="navigation"> <div class="container" ...

Ways to retrieve updated fields sent with automatic refresh functionality

Is there a way for changes made by users on a webpage that automatically refreshes to be submitted and sent to the server without using ajax calls? The current method of making an ajax call every time a field is changed seems like overkill. If you have any ...

Mysterious line appearing beneath alternate rows in Table with border-collapse and border-spacing applied. Unable to pinpoint the culprit property causing the issue

After searching for a solution to add space between the rows in my table, I finally found the answer on Stack Overflow. The implementation seemed to work fine at first glance, but upon closer inspection, I noticed an issue depicted in the screenshot below: ...

Is there a way to display menu items in a list when hovering over the parent element using CSS?

Is it possible to make the code below run when hovering over (#cssmenu ul > li > ul > li ) with the mouse? #cssmenu ul > li > ul > li > ul { right: 1170px; } ...

Sorting static content with jQuery Sortable

Currently, I am working on a website using Bootstrap and jQuery. One of the challenges I face is creating a horizontal list of divs at the bottom of the webpage, similar to the slide bar in Microsoft Powerpoint. The number of elements in this list is fixed ...

Update the HTML table by changing the first cell in the first row to span multiple

I currently have a table structured like this: <table> <thead> <tr> <th></th> <th>Col1</th> <th>Col2</th> <th>Col3</th> <th>Col4& ...

Tips on eliminating the background of a div nested within another div

<div class="white"> <div class="transparent"> ---- </div> <div class="content"> ---- </div> </div> I am working with a parent div .white that has a white background color. Inside this parent div, there are mul ...

Contact Form Appears to Be Functioning Properly, Yet Emails Are Not Being Received (HTML5 & PHP)

Hello everyone, I need some assistance with creating a contact form. This is my first time working on this, and I am facing an issue. I am using HTML5, which I have some knowledge of, and PHP, which I am not very familiar with. When I try to test the form ...

Why won't my sticky element function properly with the position attribute set to sticky?

Hey there! I've been diving into learning all about CSS positions and have nailed down most of them. However, for some reason, the sticky position just won't cooperate and is stubbornly acting like a relative one instead. Check out my HTML snipp ...

How to make CSS group checkboxes operate autonomously

I found a checkbox code on Codepen that I really liked, but encountered an issue when trying to use multiple checkboxes at once. Despite customizing it to my preferences, each checkbox only works independently and does not function properly when there are ...

What is the best way to ensure that these social icons are perfectly centered on the page across all web browsers?

Visit my website here: foxweb.marist.edu/users/kf79g/contact.php I'm stuck on the final step needed to deploy my website and finish it. The issue I'm facing is with the social icons when viewed on medium and small screens. I want them to be cent ...

Encountered an error: [$injector:modulerr] while using AngularJS

I need help creating a registration form using AngularJS. I am encountering an error in my app.js file: (function (){ 'use strict'; angular.module('modulemain',[]).controller('ModuleController',ModuleController); ...

What is the best way to connect a JavaScript file to an HTML file in an Express app?

I have my NodeJS server set up with Express, utilizing Handlebars as the rendering engine. app.use(express.static(publicDirPath)) (...) app.engine("hbs",hbs({ extname: "hbs", defaultView: "main", layoutsDir: path.join(srcDirP ...

What is the best way to ensure that a div appears below, rather than alongside, another one

I need help positioning my divs on the webpage. Currently, my map div is appearing next to the list instead of below it. The height of the list can vary as it is generated dynamically. I want the map div to be on the right side with the list displayed on t ...

rearranging items from one list to another list

I've encountered an issue in my HTML code that I need help with. I have included some classes for clarity, but their specific names are not essential. My goal is to make the "sub-nav" element a child of the "mobile parent" list item on mobile devices. ...

The text alignment is set to center, however, the wrapper, input boxes, and button are not aligning themselves in the center. The logo

Within this webpage, there exists a logo image file with a specified height to ensure proper fit. The logo positions itself beautifully within its designated div, with the wrapper div containing text-align: center, resulting in perfect alignment. Additiona ...

Mobile-friendly persistent navigation located beneath the header, inspired by the iOS7 browser design

This issue is really causing me a headache and slowing down progress on my project because I can't seem to figure it out. Currently, I am working on designing a mobile-friendly website and conducting tests in iOS7/OSX. The layout I am aiming for inc ...

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 ...

AngularJS - ng-repeat not updating when property array changes

I have a loop in my HTML using ng-repeat: <div class="row"> <div ng-repeat="item in model.painel track by item.codigoIncidente"> <strong>{{item.restante.horaMinutoSegundo}}</strong> </div> </div> In ...

Can anyone help me identify the issues in my PHP code?

My PHP code doesn't appear to be functioning correctly. Instead of displaying any errors, it simply shows a blank page. Can you identify what I might be doing incorrectly? <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_ ...