Why is my CSS and Bootstrap full-page image not displaying properly?

I've been struggling to get a full-page image to display on my website and resize responsively across different screens. I've searched through w3schools and Stack Overflow for solutions, but no matter what I try, it just doesn't seem to work. I even checked for CSS overrides in the browser developer tools, but everything appears to be fine. The div containing the background image is set as col-12 within Bootstrap - could that be causing the issue? Here's a snippet of my CSS:

body, html {
    height: 100%;
}

#image-div {
    background-image: url("paper.jpeg");
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    height: 100%;
    color: white;
    background-color: rgba(0,0,0,0.5);
    background-blend-mode:darken !important; 
    font-size: 20px;
}

And here's the HTML structure:

<div className="row" id="calculator-row">
          <div className="col-12" id="image-div">
            <div className="over-image">
              <p class="try-calculator">
               Calculate the possible return of investments
              </p>
            </div>
          </div>
          <div className="col-12" id="calculator-div">
            <h1>Return of Investments</h1>
            <BenefitCalculator />
                <strong>*The average conversion percent is 4, but enter yours in case you know it</strong>
          </div>
        </div>

**EDIT**: I forgot to mention that I am also using REACTJS.

Answer №1

Have you tried using background-size: cover, contain;? If that doesn't work, please provide a sample of your code. It's generally not recommended to set height in percentage, especially if you want the element to fill the entire page - try using 100vh or another method instead. Additionally, keep in mind that you may need a media query for different orientations like portrait and landscape.

Answer №2

Here is a helpful snippet for you:

body,
html {
  height: 100%;
  margin: 0;
  padding: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -15px;
  margin-left: -15px;
}

.row-fw {
  width: 100vw;
  height: 100vh;
}

.col-12 {
  flex: 0 0 100%;
  max-width: 100%;
}

#image-div {
  background-image: url("https://placekitten.com/g/1920/1080");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  height: 100%;
  display: block;
  width: 100%;
  color: white;
  background-color: rgba(0, 0, 0, 0.5);
  background-blend-mode: darken !important;
  font-size: 20px;
}
<html>

<body>
  <div class="row row-fw">
    <div id="image-div"></div>
  </div>
</body>

</html>

You can also utilize height: 100vh; and width: 100vw; (vw = viewport width, vh = viewport height) to achieve the desired effect.

If the parent element becomes larger than the screen size, the background will adjust accordingly. Using 100vw and 100vh ensures that only the viewport width and height are considered.

Answer №3

To make an image responsive and scale nicely to the parent element, simply add the class ".img-responsive" to the parent div of the image.

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

"Creating dynamic webpage designs with CSS for responsive layouts

Currently, I am in the process of building a website utilizing a CSS fluid layout approach which is rooted in adaptive and responsive web design principles. For this project, I am avoiding using fixed values such as pixels (px) and instead opting for perc ...

Creating a blurred background effect when a React portal is presented

I have implemented React portals to display a modal popup after the form is submitted. However, I am facing an issue with blurring only the background while showing the modal, similar to what is shown in picture 2. Initially, I tried using document.body.st ...

The custom tab component in React is currently not accepting the "disabledTabs" prop

I have designed a tab component as shown below: tab/index.jsx import React from 'react'; import TabHeader from './header'; import TabBody from './body'; import TabHeaderList from './header/list'; import TabBodyList ...

ReactJS Alert: It is advisable for each child in an array or iterator to possess a distinct "key" property

var divArr = [ '<div>布吉岛啊</div>', '<div>呵呵呵</div>', ]; ReactDOM.render( <div>{divArr}</div>, document.getElementById("example") ); but ...

The focus is on the last row that was selected

I've noticed that when I check and select a row in ui-grid, only the last selected row is focused with a background color. Should all rows be automatically painted by default? Thank you. ...

I encountered an error stating "angular not found" when attempting to dynamically load my Angular scripts

My Angular application is running smoothly. However, I found it tedious to include multiple script tags in my HTML documents every time. To simplify this process, I decided to create a small script that would automatically generate the necessary tags for m ...

Sending data from an element within an ngFor loop to a service module

In my component, I have a loop that goes through an array of different areas with unique IDs. When you click the button, it triggers a dialog containing an iframe. This iframe listens for an event and retrieves data as JSON, then sends it via POST to an IN ...

How to Create a Speech Bubble in SVG Using SnapSVG

In the process of developing a chat program, I have animated figures moving across the screen engaging in conversations. One crucial aspect I am yet to implement is creating scalable speech bubbles for when users interact. Being relatively new to SVG and ...

unable to upload the image on firestorage

I am in the process of creating a social media website similar to Facebook or Instagram. While the email, password, and name authentication during signup worked smoothly, I encountered an issue with uploading the profile picture. I suspect that the problem ...

Utilizing Ajax Blob URL for Audio Streaming

My goal is to retrieve audio data using an Ajax request and load it into an audio element. However, I'm running into an issue where the player does not seem to work properly. The play button remains disabled as if nothing has been loaded. Below is a s ...

React with TypeScript: The struggle of getting LocalStorage to work

Currently, I am dealing with persistence in a todo application developed using React and TypeScript. To achieve the desired persistence, I have implemented localStorage. Allow me to share some code snippets: const [todos, setTodos] = useState<todoMod ...

React Router version 4 is not displaying the route

While working with router v3, I decided to refactor the routing logic to align with v4 for implementing transition-groups. After writing the code below, there were no errors during compilation or in the console. However, when I navigate to /#/about, it dis ...

Dynamic column group in Datatable - toggle visibility based on user selection

In my application, I am utilizing Jquery datatable with a table that includes the following columns: Name, Office, A1, B1, Diff1, A2, B2, Diff2, A3, B3, Diff3, A4, B4, Diff4 Additionally, there is a select box containing the options: 1. All 2. Diff1 3. D ...

NextJS encounters a TypeError while using ChartJS due to its inability to read properties of null, specifically 'useRef'

Recently, I've been working on incorporating graphs using ChartJS into my NextJS application. However, I've encountered some difficulties with rendering them. Despite following several tutorials and articles, I keep encountering the same error. ...

Support for Chrome in Angular 8

Can someone please advise on the minimum version of Google Chrome that is supported by Angular 8? Additionally, I am looking for a way to prompt users to update their Chrome browser if it doesn't meet the required version. My Angular application seems ...

Tips for effectively combining an array with jQuery.val

My goal is to have multiple form fields on a page, gather the input results into an array, and then store them in a database. This process was successful for me initially. However, when I introduced an autocomplete function which retrieves suggestions from ...

Rendering JSON responses in React.js can be achieved using either the fetch function or axios library

I've spent way too much time struggling and I can't seem to concentrate anymore. My goal is simple - I just want to fetch JSON data from a URL and display it visually in the browser. It doesn't even have to be formatted, at least not until ...

Transferring param.id information between frontend and backend using React, Node, and Express

I have been facing difficulties in passing the userID parameter back from my backend while trying to return a user list on a component. I am using the useEffect hook to fetch data from Redux and then call an action on the component with the declared param. ...

What is the best method to make a hyperlink within an IFrame open in a new window?

Let me share the code I've been working on: <!DOCTYPE html> <html> <head> <base target="_blank"> </head> <body> <div style="border: 2px solid #D5CC5A; overflow: hidden; margin: 15px auto; max-width: 800px; ...

Fixing CreateJS in Adobe Animate HTML5 Advertisement for Internet Explorer versions 9 and 10

As I work on creating an HTML5 ad using Adobe Animate CC, I encounter a minor setback. While testing the ad, I notice that it displays perfectly in most browsers except for Internet Explorer versions 9 and 10. It's interesting to see that according ...