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

Ways to prevent a timeout when the score exceeds 1000

Could someone help me with clearing the interval and resetting the score in my code? It seems to be working fine, but when the score goes over 1000 and I hit reset, it doesn’t reset completely. I've tried placing the clearTimeout functions before e ...

``It seems like there was an error with WebComponents and NextJS - the hydration failed due to a mismatch between the initial UI and what was rendered on

I'm running into an issue with the following error message: Error: The initial UI doesn't match what was rendered on the server, leading to hydration failure. This problem occurs when I have a NextJS webpage that includes StencilJS web compone ...

Internet Explorer 11 fails to include Authorization header when making API requests

Technology Stack : ReactJS, axios, API deployed on AWS In my ReactJS application, I am making API calls to an AWS deployment using axios. The app works flawlessly in Chrome and Firefox, but encounters issues in Internet Explorer 11. All APIs have been pr ...

Exploring the functionality of client.query in Apollo Client without the use of JSX components

I'm currently exploring how to execute a query with Apollo Client in React without returning a JSX component, but rather just an object (the data object that is returned when querying the Apollo Server). I attempted using the <Query /> componen ...

Is it possible to integrate swup with React.js?

I am currently experimenting with integrating swup js into React.js. After importing swup and adding const swup = new Swup();, I encountered the following error message. How can I resolve this issue? Below is how I added it: import Swup from 'swup&apo ...

The event.pageY position consistently reflects the laptop screen size rather than the exact position where the click occurred

My webpage is scrollable, but the event.pageY position always corresponds to my screen size. Even when scrolling down and clicking near the top of the screen, it registers as 50px. I am currently utilizing event.pageY While this functions correctly on a ...

The curious case of ReactJs/NextJs useEffect(): Unveiling its mysterious double invocation

My custom useEffect() hook is consistently executed twice. It relies on two dependencies: reinitializePage (which triggers the useEffect when set to true) and corporateContext (which updates the component when the context changes). const [reinitializePage, ...

Integrate your React Native application with a Node.js backend on your local machine

My attempt to establish a connection between my react native app and my node.js app on a Windows system has hit a roadblock. While I am able to receive responses from the node API using Postman, the response from the react native app is coming back as unde ...

Expression Engine presents a dilemma with breadcrumbsOr:Expression Engine

Having a slight issue with Expression Engine. I've created a breadcrumb snippet using {if segment_} coding. While setting up if rules for each page on the small site, I encountered a problem with one of the breadcrumb trials. The issue arises when tr ...

Center the image and align the floated texts on each side horizontally

I've recently started learning about HTML and CSS, but I'm having trouble grasping one concept. My goal is to align two floating <p> elements on either side of a centered <img>. Here's an example of what I'm trying to achiev ...

Unicef's animated web content

Looking to learn more about gate animation and zoom page transition on the Unicef website? I want to incorporate these cool animations into my own project. Can someone provide me with a "keyword" or point me in the right direction to find information on ...

Is there a way to work around the CORS policy in order to fetch data from URLs?

I have been developing a tool that can analyze URLs from an uploaded CSV file, search the text content of each URL, and calculate the total word count as well as the occurrences of "saas" or "software". The goal is to generate a new CSV file with the origi ...

Accordion symbol for adding or subtracting

Looking for a way to change the Toggle text in my angular 7 application accordion to images or content displaying a + sign for collapse and - for expand. I need to achieve this using CSS in my SCSS stylesheet so that I can later change the color of the sig ...

Is it not possible to call this authentication expression in a Typescript file when using Next JS?

I am currently developing a sign-in method for my Next.js application and I have been referring to the GitHub repository's recommended documentation. However, upon reaching the authentication folder step, I encountered an error regarding the sign-in ...

When using iOS, the video compressing process stops automatically if the screen is no longer active while the file input

I am working on a web application that includes a file upload feature for large videos, typically 30 minutes or longer in duration. When a user on an iOS device selects a video to upload, the operating system will automatically compress it before triggerin ...

Encountering problems with `npm run build` when using `con

Running a react app with express as the backend has been quite the adventure. After following this particular tutorial on how to connect the two and deploy to heroku, I found myself in a bit of a conundrum. Express is running smoothly on port 5000 as instr ...

The css-loader in Webpack fails to recognize the localIdentName option

Currently, I am utilizing the css-loader as a Webpack plugin to modify my CSS class names. However, I am facing an issue where the localIndentName option is not having any effect. Below is the snippet of my webpack configuration related to the css-loader: ...

What is the best way to showcase a div on top of all other elements in an HTML page?

As a newcomer to html and css, I have successfully created a div that contains city names. The issue I am currently facing is when I click on a button to display the div, it gets hidden behind the next section of my page. Take a look at the image below for ...

Leveraging the power of React and Flutter to create Android instant apps and Apple App Clips

Is there any restrictions when it comes to using React and/or Flutter for Android Instant App as well as Apple App Clips? I haven't been able to find much information on this aside from the size limitations (15MB for Android and 10MB for Apple). Fur ...

I'm having trouble with my code not fitting all screen resolutions. I usually code on a Macbook, but recently switched to a Windows computer and now everything is out of whack

$(function(){ $("#Welcome").typed({ strings: ["PROGRAMMERS / NETWORKERS"], typeSpeed: 60 }); }); html { background-color: mintcream; background-size: 100%; } /* Home */ .homeheader button { background-color: #4CAF450; top: ...