Struggling to get your background image to display correctly with CSS?

Having some trouble with the code in my index.html file. The style.css pages are correctly linked, and all other elements are working fine.

.fullbox {
  border: 1px solid orange;
  background-image: url(background-image:url(/images/topmain.jpg) no-repeat;
}
<div class="row">
  <div class="col-12">
    <div class="fullbox">
      <h2>plumbing</h2>
    </div>
  </div>
</div>

Answer №1

You have made a mistake in your CSS

background-image: url(background-image:url(/images/topmain.jpg) no-repeat;

The correct syntax should be:

background-image: url('images/topmain.jpg');
background-repeat: no-repeat;

OR

background: url(/images/topmain.jpg) no-repeat;

Please update your code snippet as follows:

.fullbox {
  border: 1px solid orange;
  background-image: url('images/topmain.jpg');
  background-repeat: no-repeat;
}
<div class="row">
  <div class="col-12">
    <div class="fullbox">
      <h2>plumbing</h2>
    </div>
  </div>
</div>

Another example with a live link:

.fullbox {
  border: 1px solid orange;
  background-image: url('https://cdn.dribbble.com/users/1928643/avatars/small/b3f1a5ea4d68ff539b8f808ff3c4b8a5.jpg');
  background-repeat: no-repeat;
}
<div class="row">
  <div class="col-12">
    <div class="fullbox">
      <h2>plumbing</h2>
    </div>
  </div>
</div>

For more information on the background-image property and path, visit:

Answer №2

background image: url(/images/mainbg.jpg) no-repeat; }

Answer №3

background: url(source/...) center center/cover no-repeat fixed;
1)Avoid using 'no-repeat' in the 'background' shorthand property, use only the 'background' syntax instead. For example, 2)You don't need to repeat 'background-image' after 'url', you can directly provide the relative address like this
background-image: url(source/...)
I hope this explanation helps :)

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

Styling speech bubbles and dividing lists with CSS

Looking to create a speech popup with an internal menu that has items separated by borders. The challenge arises when there is an even number of items - how can the border extend inside the speech pointer? After some consideration, also need to account fo ...

Implementing CSS to achieve striped row styling in a paragraph (not within a table)

Is there a way to achieve alternating row shading within a wrapped paragraph element without using the :nth-child technique? For instance, if we have: <p style="width:100px;"> row 0 -- hello row 1 -- world row 2 -- !!! </p> Some brow ...

ng-Pattern in AngularJS

Enter a number as your username in the field below: <fieldset class="col-sm-12 col-xs-12 text-center"> <label for="username">Username</label> <input type="text" id="username" ng-pattern="/^[0-9]*$/" ...

Grab the table headings from an HTML table and store them in variables after accessing the DOM

Looking to modify the structure of the DOM. Wanting to display table content using paragraphs instead. To achieve this, I need to extract data from each row in the table. How can I accomplish this task? <table style="width:300px"> <tr> ...

Adjust words to fit any screen size as needed

Looking for a small program that can dynamically change a word within an SVG? The goal is to create an effect where regardless of the word or group of words, they always stretch along the entire height (due to a 90-degree rotation) by adjusting the font si ...

What is the process for connecting an HTML page to a CSS file located in a parent directory?

Here's the problem I'm facing: I recently encountered some organizational issues with my website, so I decided to reorganize my files for better classification. The current folder structure looks like this: www resources images ... css de ...

Can anyone recommend which browser compatibility is best suited for my Application?

I'm unsure if this question is relevant, but here goes... When creating an application, should I focus on browser compatibility for IE, Chrome, Firefox, Netscape, Opera, or something else? And if I choose IE, which version should I target - IE6 ...

What would be the best way to create a JavaScript function that emulates the functionality of an Upgrade Button?

I am currently working on developing a clicker game and have reached the point where I need to implement a function for the 'upgrade click' button. This function should deduct a certain amount of money when clicked, while also increasing the amou ...

Achieve mobile responsiveness for search fields with Bootstrap 4

Attempting to center my search field using the code below did not yield a responsive result. On mobile, it remains right on top with the footer, unlike on desktop where I'd like to see some space between them. This discrepancy only surfaces in small ...

What is the best way to integrate multiple Angular2 components on a single page?

I'm currently working on fitting a couple of components to each take up a full page. I would like the first component to occupy the entire screen, similar to a landing page, and have the browser scroll bar for scrolling down to view the second compone ...

Show the profile picture of a model in a Django template

I am trying to display the user's image by inserting it into the src attribute of the img tag, but I am facing difficulties with it. Here is my code: models.py class allusers(models.Model): user = models.OneToOneField(User, on_delete=models.CASC ...

Eliminate the content located between two specific words in the img src URL and then render the file from the new source by utilizing ht

My img tags have parameters in the url for ajax image crop functionality. Here's an example: <img src="/resize/45-800/files/myImage.jpeg" alt="Chania"> Add /resize/45-800/ before the url to instruct the ajax script to fetch the file from the f ...

How can I incorporate my styles into a separate css file for use in a React project?

Although it may seem simple, I am interested in incorporating SCSS into my React application for styling purposes. I understand that React will interpret all of my styles and render them in separate <style> tags within the <head> section. I hav ...

What sets apart referencing an image file in the src attribute of an img tag from directly embedding an image within an image tag?

Does the server see any distinction between using <img src=pathto.png /> and <img src=data:image/png;base64,encodedpngdata... />? If src=pathto.png is used, will the server encode the image before sending it to the browser? ...

JAWS is able to scan a drop-down menu without duplicating options before reading

I encountered an issue where JAWS reads a sentence as hello hello combobox choose dot dot dot test question. Is there a way to prevent JAWS from repeating the word hello? The desired output is hello combobox choose dot dot dot test question. Here is the ...

Is there a way to distinguish between automated bots and human users who are visiting my website?

Is there a way to detect if a bot is navigating my website? My website requires users to submit a form in order to access the next page. To speed up the page load time, I perform additional background database queries when a user submits the form. Howev ...

Implementing uniform column width in a Material-UI Grid

Looking for a way to create a single column layout with items of equal width using the Material-UI Grid system? Check out this sample code: <Grid container align="center" direction="column"> <Grid item className={classes.item}> < ...

How can JavaScript be used to activate HTML5 AppCache?

<html manifest="example.appcache"> Is it possible to use javascript to include the manifest="example.appcache" part? ...

The shade of grey on the curve appears instead of the usual red on the iPad. Any ideas on how to fix

I am having trouble creating a curve like the one shown below on my iPad. The color appears to be gray and does not work properly. Is this a bug with ChartJS or is there a solution to fix this issue? This problem occurs when the type value is set to "lin ...

Ways to incorporate a dynamic HTML form that allows for input elements to be added both horizontally and vertically while maintaining connected lines

Looking to design a form that showcases HTML elements in both vertical and horizontal positions, with lines connecting them as seen in this example: https://i.sstatic.net/jB12f.png. Can anyone offer guidance on how to achieve this? Thanks! ...