The problem of the background image not appearing persists even after setting the doctype

Why is the background image not showing when declaring the doctype in vscode for this website, even though it appears in quirks mode?

The image can still be accessed through the link in inspect element.

I have attempted different approaches such as revising the code, changing the image, adjusting its position, and modifying stylesheet values.

Any insights on why this issue persists?

HTML

<!DOCTYPE html>
<html>
    <head>
        <title>Hot Beans Web - Home</title>
        <link rel="stylesheet" href="stylesimages/home.css">
    </head>
    <body>
        <div class="header">
            <img src="stylesimages/logo.png" width="400px" height="100px">
        </div>
        <div class="bgimage"></div>
        <div class="bg-text">
            <h1 style="font-size:90px">We code the future.</h1>
            <p>Providing rich, advanced and sophisticated IT solutions that will make your website shine.</p>
          </div>
        <p>asjjssj</p>
        <h1><a href="https://www.youtube.com/" target="_blank">Hot Beans Web</a></h1>
        <button>shshs</button>
        <a href="https://www.youtube.com/" target="_blank">Link to Youtube</a>
    </body>
</html>

CSS

.bgimage {
    background-image:url("homebackground.jpeg");
    height: 100%; 
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
}
.header {
    padding: 0px;
    text-align: left;
    background: #ac1b1b;
    color: rgb(0, 0, 0);
    font-size: 20px;
    text-indent: 20px;
}

body{
    font-family: 'Roboto', sans-serif;
}

.bg-text {
    color: white;
    font-weight: bold;
    border: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    width: 80%;
    padding: 20px;
    text-align: left;
}

file paths

Answer №1

I haven't tested your code, but it seems that since the div with the image background is closed immediately without any children (

<div class="bgimage"></div>
) and its height is set to 100% in CSS, it will have a height of 0px. You can try changing the height value to 100vh (viewport height) to see if it resolves the issue. Additionally, if you want the image to be the background of the entire page, consider moving the bgimage class from that div to the body element.

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

The arrangement of CSS code is crucial for it to work properly; any deviation from the correct order

I am facing a problem where I am trying to display a circular div using CSS, but it only works if the background image property is set first. Typically, this wouldn't be an issue if the image wasn't being dynamically inserted using PHP code. I ...

Tips for sharing a React component with CSS modules that is compatible with both ES Modules and CommonJs for CSS modules integration

Some frameworks, like Gatsby version 3 and above, import CSS modules as ES modules by default: import { class1, class2 } from 'styles.modules.css' // or import * as styles from 'styles.modules.css' However, other projects, such as Crea ...

How can I correctly link and open a PDF file in HTML without an extension provided in the filename?

Looking for some advice. I have a client project where there are PDF files uploaded to a file structure within a LAMP Stack, but the files do not have extensions. I need the browsers to recognize that these files are PDFs and open them accordingly. Adding ...

Having issues with the Jquery tablesorter plugin when attempting to prevent headers from being sorted

Can anyone help me with a sorting issue I am having with a table on my website? I am using the jQuery plugin tablersorter to sort the table, but I have two headers that I do not want to be sortable. I tried to disable them using the example provided on the ...

"Trigger a hover effect on one element, but have it impact a

I have a simple question that I couldn't find a direct answer to, so here it is: I have two boxes and I want to hover over the first one but have it affect the second one (meaning when hovering over the first box, the second box should scale up with a ...

Aligning the Navigation icons on my webpage

<nav> <ul> <li><a href="index.php">Home</a></li> <li><a href="index.php?about">About</a></li> <li><a href="index.php?products">Products</ ...

Detecting the screen resolution of the window beyond a div overlay by accessing the HTTP_REFERER data

When a user clicks on a specific div at the bottom right of a webpage, a form is displayed as an overlay using jQuery. This form contains an iframe, and I need to track the page that the visitor clicked from (similar to HTTP_REFERER) as well as the resolut ...

I am keen on eliminating the lower margin of the PIXI application

Exploring the possibilities of PIXI.js, I am working on creating a new application. However, upon adding the PIXI application to the DOM, I noticed an unwanted margin at the bottom. Here is an image illustrating the issue. Is there a way to remove this bo ...

Issues with the creation of an AngularJS table are causing functionality to malfunction

2021 UPDATE: Note: This question was drafted when I was still learning HTML and JS. If you are seeking assistance for an issue, this might not be very useful as my code was messy. Sorry for any inconvenience caused. The question will remain posted in acco ...

Show the results of fs.readdirSync() within an HTML file on the frontend

As someone who is just starting out with node.js, I've been searching online for a solution to the issue I've described in my question title. The project I'm working on involves creating a basic web API that allows users to upload their fil ...

What is the proper way to include a URL when submitting an AJAX form?

When I try to call a servlet using HTML, jQuery and Ajax by submitting a form, I keep getting a 404 error saying the resource cannot be found. My project is built with Maven. The Servlet is located in the src/main/java package under : com.mycompany.sample ...

My menu stretches out in a single line, and I prefer it not to collapse but instead continue on to the next line when it becomes smaller

Unfortunately, I'm facing this issue: I have a lengthy menu that is extending to the next line instead of collapsing, but it is not looking good. Here is the CSS code: .navigation li { display: inline; margin-top: 5px; } .navigation a:link ...

Creating a Bootstrap grid system for multiple divs with offset styling

Looking to design an HTML page layout with a sidebar menu and a fixed KPI metrics div in the first row. Want the KPI metrics div to stay fixed when scrolling through tables below. Also, seeking guidance on aligning the KPI metrics div and the table div t ...

Inline width being applied to elements in IE9 when display settings are set to 125% magnification

It seems that when a user adjusts their display settings to 125% from the Control Panel, IE9 will automatically add extra width inline to elements like this: <div class="container" id="main" style="width: 1500px"> <!-- Insert code here --> &l ...

Fade-in effect on one DIV element impacting the values of other div

As a newcomer to jquery and JavaScript, I'm facing some challenges in getting the desired functionality. Currently, I am trying to animate three images simultaneously - one moving downward (iphone), another fading in (shadow), and the third one animat ...

How do I prevent my image slider from scrolling to the top of the page when I click next or prev?

<script> export default { name: "ImageSlider", data() { return { images: [ "https://cdn.pixabay.com/photo/2015/12/12/15/24/amsterdam-1089646_1280.jpg", "https://cdn.pixabay.com/photo/2016/02/17/2 ...

Issue with JQuery on Mobile Devices: Troubles with Dropdown Menu and Loading Function

Having some trouble with my JQuery code on mobile devices. The drop down menu isn't showing up on an iPhone, the load function isn't working to display the additional PHP page on a Samsung Edge 7, and the drop down doesn't seem to be functio ...

Utilizing complex data with Angular 5 [Select+Option] - a comprehensive guide

I have a complex dataset stored in the app.component.ts file that looks like this: export class AppComponentimplements OnInit { tests = { 'name': 'Bob', 'grade': '5th', 'score' ...

"Utilizing the React library to implement an HTML component with a styled radio input that

My radio button issue: I have two radio buttons, one is checked by default. When trying to switch the selection by clicking on the unchecked option, I have to click twice. How can I resolve this problem? <label>YES</label> <input type={&a ...

A step-by-step guide to creating an interactive Rubik's Cube using THREE JS and loading custom images onto each individual

I am facing a challenge with developing a 5x5 Rubik's Cube. The cube has six faces, which means I need to display 25 images on each small box of each face, totaling 150 images for the entire 5x5 cube. Although the Rubik's Cube itself is displayed ...