The background image in CSS refuses to display

My CSS background image isn't displaying properly. Here is the code snippet from my HTML:

<div  class="container-fluid p-c b-g">
  <div class="row">
    <div class="col-sm-12 text-infom">

    </div>
    </div>  
  </div>
</div>

CSS code snippet:

.b-g{
   background-image: url(../images/bg/trading.jpg);
    width: 100%;
}

Answer №1

increase the height of the div to make it visible

.b-g{
  background-image: url(https://pbs.twimg.com/profile_banners/1285511592/1470391779/1500x500);
  background-size: contain;
  background-repeat: no-repeat;
  height: 300px;
}
<div  class="container-fluid p-c b-g">
  <div class="row">
    <div class="col-sm-12 text-infom">

    </div>
   </div>  
</div>

Answer №2

It's possible that the file path you are using is incorrect, consider checking if the file has loaded by inspecting it in your browser.

<style type="text/css">
.b-g {
   background-image: url("http://example.com/images/photo.jpg");
   width: 100%;
}
</style>
<div class="b-g">
</div>

Answer №3

To properly fit an image to a background, whether it is an element, body or any other container:

.b-g {
    padding: 0px;
    background-image: url(../images/bg/trading.jpg);
    width: 100%;
    height: 100vh;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    background-attachment: fixed;
}

Alternatively, you can utilize the background-size property (while removing the width property).

background-size: 100% 100%;

Another method is to implement it like this:

background: #000 url('../images/bg/trading.jpg') repeat center center;

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

What methods can I employ to utilize the name attribute for POST requests instead of the ID attribute in TinyMCE?

My inline TinyMCE form sends content to qry.php with the key "edit_me". I prefer the default behavior of sending content using the name attribute instead. <script type="text/javascript"> tinymce.init({ selector: '#edit_me', ...

What encodings does FileReader support?

Are you looking to easily read user-input files as text? If you can count on modern browser usage, then using FileReader is the way to go (and it works exceptionally well). reader.readAsText(myfile, encoding); It's worth noting that encoding defaul ...

Is the mobile site displaying CSS pixels in the physical pixel resolution?

I am struggling to grasp the problem and finding it challenging to explain it clearly, so I have attached a picture depicting the issue. https://i.stack.imgur.com/E9Gzj.png My current approach involves using ratios of 100% and 100vw for element widths. D ...

inactive toggle being released

I am facing an issue with my two slider menus, where only the right menu holds the active value when clicked. The left menu slides out only when the toggle button is held down, but I need it to slide out when the toggle is simply clicked and not held down. ...

Tips for lining up two images and text on the same row

I am facing a simple issue - how can I align an image and text in one line like this [image - text - image] and repeat the pattern. <html> <head> <title></title> <style> img { width: 100px; h ...

Function for masking phone numbers is adding additional "x's" to the input field

My phone number formatting script is supposed to add dashes after the third and sixth characters, as well as insert an "x" after the 10th character for extensions. However, it is adding extra "x's" after the 12th character, resulting in the incorrect ...

What are the steps to sending HTML emails from the default mail client on Mac and PC operating systems?

Currently, I am in the process of creating a website that allows clients to easily send an email with the content they are viewing. I want users to click on a button which will open their default mail client (compatible with both Mac and PC) and automatica ...

Aligning float:left divs vertically

I have multiple divs with equal widths but varying heights that I need to fit together tightly. When I set them to float left, they don't align vertically but instead line up at the bottom of the row above. Even with the example below, I want to eli ...

Dynamic Dropdown Validation During Form Submission

In the form, there are multiple rows displayed dynamically, each with a dropdown menu. The id for each dropdown is "ReasonCd#" where "#" increments from 0 based on the row number. By default, every dropdown has "Select Number" as the selected option, with ...

analyzing information from a variety of HTML tables

I am currently working on extracting financial data from Income Statements tables within 8-K Forms retrieved from the Edgar Database (http://www.sec.gov/edgar/searchedgar/companysearch.html). Here are a couple of examples: Apple Alcoa The specific table ...

Using Angular 6 to load external HTML files with CSS inside a router-outlet

I'm currently working on creating a json-based dynamic template using Angular 6. There are certain scenarios where I need to fetch external html content (which could be stored in a database) along with its corresponding css (also stored separately in ...

What is the best way to add hyphens between words in PHP code?

Here is the code snippet and the desired output: ('nice apple'),(' nice yellow banana'),(' good berry ') To achieve the desired output: ('nice-apple'),(' nice-yellow-banana'),(' good-berry ') ...

Show the form for user input

I have an HTML code for a form that requires input. Once the 'OK' button is clicked, the values are sent to a PHP script using $_POST. Is it possible to display the same form again if the input format is incorrect, but do so only within my PHP sc ...

The stature of Bootstrap's columns

Exploring Bootstrap has been an exciting journey for me, as I believe it will simplify the process of creating visually appealing web pages. I'm currently facing a challenge in understanding these two examples: Bootstrap 3: http://codepen.io/rhutchi ...

Unexpected behavior observed when animating CSS transform in IE

I am currently facing an issue with a CSS animation on my website that animates an arrow back and forth. The animation is working perfectly on all browsers except for Internet Explorer, where there seems to be a glitch causing the Y position of the arrow t ...

Tips for dividing HTML code on a page into individual nodes

I am looking to extract the HTML content from a website and then parse it into nodes. I attempted the following code: function load() { $(document).ready(function () { $.get("https://example.com/index.html", function (data) { const loadpage ...

Html page only visible to authorized users

Is there a way to upload an html file to my website without making it visible to everyone? I don't want search engines like Google or Bing or any web spider to index it. I don't want to password protect it either. I just want it to be truly invis ...

Limiting zero is ineffective when it comes to pop-up issues

Hey there, I'm looking to prevent users from inputting zero and dot in a specific field, which is currently working fine. However, when the field is within a pop-up, the code below doesn't seem to work. <script> $('#name').keyp ...

Choose the selectize item to always move to the front

Hey there, I'm currently using the selectize plugin to incorporate tags into my website. Everything is working well, except for the issue of the drop-down item being obscured by some of my other divs. I'm looking to have them function more like ...

Scrolling vertically using window.open functionality

I am trying to open a pop-up window using window.open. I would like the scrollbars to appear only if necessary. Unfortunately, in Safari, the scrollbars do not show up unless I include scrollbars=1 in the code. However, this also causes horizontal scrollb ...