Images located in the "/images" folder are not being properly served as the URL is being interpreted as relative to the "/css" directory

All of the CSS files are located in the src/main/resources/public/css directory, while the images are stored in src/main/resources/public/images.

When attempting to access images from style sheets, like this example:

background-image: url("/images/dp.jpg");
, the URL becomes relative to the css directory and as a result, the images are not being served.

Currently, the only way it works is by placing all the images in the css folder itself and specifying the background as background-image: url("dp.jpg");. However, I prefer not to change the directory structure this way.

I have also attempted using a fully qualified URL such as
background-image: url("http://localhost:8080//images/dp.jpg");
, but this method was unsuccessful.

Is there a simpler way to access images in the /images directory from stylesheets in the /css directory?

Answer №1

When using url() in CSS, paths are relative to the directory of the CSS file where it is located. This means you can adjust your URLs like this:

background-image: url("../images/dp.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

I am looking for a way to add some color to the text within a div on my HTML page. Can you help me

Is there a way to apply background color only to the text content within this div, without styling the entire element? ...

Issue with column-break-before toggle function only operational in Safari

In my website layout, I have arranged li elements in a 2 column design. I am looking to implement a specific functionality where if a div element (inside an li element) is clicked, it should add a class with the following CSS properties: -webkit-column-br ...

Tips for making a draggable div come to the forefront upon clicking

I'm looking to make a jQuery draggable div come to the front when it's clicked. I came across this post, and tried creating a JsFiddle based on it, but couldn't get it to work. Any ideas on what I might be missing? Thanks! Here's the l ...

Is it possible for a jQuery selector to retain its object? What can be done to prevent it

One interesting scenario involves a dropdown element within a container. <div class='container' /> <script> var dropdown = "<select class='multi-dropdown'> ... </select>" </script> Every time the value ...

The functionality of cloning in jQuery may encounter an issue where the text field remains enabled if the user selects an option labeled "other

Currently, I am working on a jQuery clone with my existing code and everything is functioning well. In the first scenario, if the user selects other from the dropdown menu, the text field becomes enabled. In the second scenario, when the user clicks ...

Tips for closing a modal in JavaScript after submitting the form

As I try to learn JavaScript, I'm creating my Quiz game and encountering an issue with a modal window. After entering my nickname and pushing Submit, I want to save the nickname in localStorage and close the modal window. However, the problem is that ...

Issue encountered while attempting to include a background image in React JS

I encountered an issue when attempting to include a background image in react js. ./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/index.css) Unable to locate module: An attem ...

Is Ruby on Rails featured in Designmodo's Startup Framework Kit?

I'm curious if the Startup Framework Kit from Designmodo can be seamlessly incorporated into my Ruby on Rails project. While I've had success integrating their Flat-UI-Pro using a gem, I haven't come across one for the Startup Framework yet. ...

Tips and tricks for utilizing a document to paraphrase a paragraph

document.getElementById("txtOutput").value = result; Is there a way to rewrite the code so that instead of using .value=result, it writes to a specific div or paragraph? ...

Select multiple items from a list in HTML using the power of jQuery with a Multi Select

I'm facing an issue with the multi-select box. I attempted to choose multiple values using jQuery, but only the last one seems to be selected. Can someone assist me, please? Below is my code: <script> $(function(){ <?php foreach ($selectd ...

When designing a webpage using HTML and CSS, the size of HTML blocks decreases as the page is made smaller

Having an issue with the following: I hope you can help me identify my problem here and I'm not sure why it's occurring. https://i.sstatic.net/C7VzU.png I believe the problem lies in the header and nav sections I initially thought it might be rel ...

Menu Overlay (jQuery/CSS)

I am in the process of developing a website that is optimized for both mobile and desktop devices. I am currently brainstorming ideas for the main navigation, which I envision as an overlay that slides down similar to . However, I am struggling to create ...

Using `new FormData(form)` to access form data without actually submitting the form

I'm facing an issue with my HTML form that has a file input. I need to handle the response from the form submission without refreshing the page. To achieve this, I've implemented an Ajax call to submit the form on my behalf. However, every time ...

“Tips for positioning text in the middle using HTML and CSS”

I'm trying to customize the text "TITLE" in my HTML and CSS code, #headerf { background-color: #717571; overflow-x: hidden; position: fixed; z-index: 99999; } .headert { position: fixed; z-index: 9999999; width: 100%; height: 60px; ...

Looking to add tiered custom attribute select boxes in SnipCart - how can I make it happen?

I am interested in implementing two custom attributes for products, where the options for the second custom attribute are determined by the selection of the first attribute. My specific situation involves selling art in various formats and sizes, with dif ...

Guide on generating tabs with the power of Javascript and Jquery

Is it possible to create multiple tabs on a page using jquery or javascript, where clicking buttons on the menu slides in a new page without changing the URL? I already have the HTML and CSS prepared. div.tabContent.hide { display: none; } nav { bac ...

How to align two divs in CSS when they are not always both present

Currently working on CSS styling for a store. I have a div that aligns the buy button to the left, and Prev and View Next images to the right. The issue arises when the "buy" button is occasionally not present due to PHP functionality. When the buy butto ...

Having trouble choosing elements with angular.element within ng-repeat loop

In my HTML code, I am using an ngRepeat element: <ol id="animationFrame"> <li ng-repeat="animationImage in animationImages" ng-repeat-listener> <img ng-src="{{animationImage.src}}" id="{{animationImage.id}}"> </li> </ol& ...

Is there a CSS4 resolution for transitioning from 0 to auto?

I searched extensively for information on CSS4, but unfortunately I came up empty-handed. Back in the era of CSS3, a common challenge arose when it came to height transitions from 0 to auto without relying on JavaScript. The introduction of transitions sa ...

What causes the lack of upward movement for a div element when the div above it is floated to the left?

Recently, I've been delving into the world of float property in CSS. This is the HTML code snippet I'm working with: .left { float: left; text-align: center; width: 25%; } .normal { text-align: center; width: 25%; } <div class="lef ...