Is your background image not filling the entire page?

Just diving into the world of HTML and CSS (with a touch of Bootstrap), I've set out to create a basic scrolling webpage. However, I've hit a roadblock with the background image not covering the full height of the page. It seems to stop at the h2 text, behaving as if that element marks the end of the page. I've tried everything I can think of to rectify this issue, but to no avail. It's a simple problem, I'm sure, but one that has me completely stumped. Any advice or guidance on how to fix this would be greatly appreciated.

Check out the codepen for reference.

body {
  background-color: rgb(255, 255, 255);
}

#front {
  background: url("https://image.ibb.co/mjTmwv/port34.png") no-repeat;
  overflow: hidden;
  background-size: cover;
  width: 100%;
  height: 100%;
}

#h1 {
  color: white;
  font-size: 50px;
  margin-top: 40vh;
  padding: 10px;
  background: rgba(43, 142, 255, 0.4);
}

#pt {
  color: white;
  font-size: 30px;
  background: rgba(39, 220, 130, 0.4);
}
<ul style="z-index:9;">
  <li>
    <a class="active" href="#"><img class="img-fluid" style="width:auto;height:auto;max-height:26px;max-width:20px;" src="https://image.ibb.co/mg1s3a/lyreimage27.png" alt="website icon"></img> placeholder inc.</a>
  </li>
  <li><a href="#">About
      </a>
  </li>
  <li><a style="text-decoration:none" href="#">Portfolio</a>
  </li>
  <li><a href="#">Contact</a>
  </li>
</ul>

<header>
  <div id="front">
    <div class="container-fluid">
      <h1 id="h1" class="text-center">Placeholder</h1>
      <h2 id="pt" class="text-center">Placeholder Text</h2>
</header>

Answer №1

Your #front div doesn't seem to have enough content to fill the entire page. It's important to ensure that you have sufficient content to cover the entire page, or alternatively, you can set a background-image for the body element. If you choose to update the CSS for your #front element, you can use the following code:

#front {
  background: url("https://image.ibb.co/mjTmwv/port34.png") no-repeat;
  overflow: hidden;
  background-size: cover;
  width: 100%;
  height: 100vh;
}

body
    {
     background-color: rgb(255, 255, 255);
    }

#front {
    background:       url("https://image.ibb.co/mjTmwv/port34.png") no-repeat;
  overflow: hidden;
  background-size: cover;
  width: 100%;
  height: 100vh;
}

#h1 {
  color: white;
  font-size: 50px;
  margin-top: 40vh;
  padding: 10px;
  background: rgba(43, 142, 255, 0.4);
}

#pt {
  color: white;
  font-size: 30px;
  background: rgba(39, 220, 130, 0.4);
}
<ul style="z-index:9;">
  <li>
    <a class="active" href="#"><img class="img-fluid" style="width:auto;height:auto;max-height:26px;max-width:20px;" src="https://image.ibb.co/mg1s3a/lyreimage27.png" alt="website icon"></img> placeholder inc.</a>
  </li>
  <li><a href="#">About
      </a>
  </li>
  <li><a style="text-decoration:none" href="#">Portfolio</a>
  </li>
  <li><a href="#">Contact</a>
  </li>
</ul>

<header>
  <div id="front">
    <div class="container-fluid">
      <h1 id="h1" class="text-center">Placeholder</h1>
      <h2 id="pt" class="text-center">Placeholder Text</h2>
</header>

Answer №2

I made some adjustments to your code to improve the structure and achieve the desired effect without using inline styles.

#front {
  background: url("https://image.ibb.co/mjTmwv/port34.png") no-repeat;
  overflow: hidden;
  background-size: cover;
  width: 100%;
  min-height: 100vh;
}

.text-center {
  text-align: center;
}

h1 {
  color: white;
  font-size: 50px;
  margin-top: 40vh;
  padding: 10px;
  background: rgba(43, 142, 255, 0.4);
}

h2 {
  color: white;
  font-size: 30px;
  background: rgba(39, 220, 130, 0.4);
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.7);
  position: fixed;
  top: 0;
  width: 100%;
  font-size: 16px;
  z-index: 9;
}

li {
  float: left;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover:not(.active) {
  color: white;
  background-color: rgba(39, 220, 130, 0.4);
  transition: 0.5s;
  text-decoration: none;
}

.active {
  color: white;
  background-color: rgba(43, 142, 255, 0.4);
}

.active:hover {
  color: white;
  text-decoration: none;
}

.active img {
  width:auto;
  height:auto;
  max-height:26px;
  max-width:20px;
}
<ul>
  <li><a class="active" href="#"><img class="img-fluid" src="https://image.ibb.co/mg1s3a/lyreimage27.png" alt="website icon" />placeholder inc.</a></li>
  <li><a href="#">About</a></li>
  <li><a href="#">Portfolio</a></li>
  <li><a href="#">Contact</a>
  </li>
</ul>

<header id="front">
  <div>
    <div class="container-fluid text-center">
      <h1>Placeholder</h1>
      <h2>Placeholder Text</h2> 
    </div>
  </div>
</header>

Answer №3

Ensure the height of your header element is set to 100vh;

To achieve this in your CSS, insert the following code:

header {
height: 100vh;
}

Answer №4

#front should be the same size as header. Consider adjusting the height of your header to 100%. Another option is to apply the background to the body element for full page coverage, which is a simpler and clearer approach.

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

Add new information after modifying it

Is there a way to retrieve the updated values from the table product and insert them into the purchases table? My code successfully updates the data, but encounters issues when trying to insert into the purchases table. <?php $ID=$_GET["stocksid"]; ...

What could be causing document.getElementById to return null?

I've been troubleshooting my code and noticed that one of the methods in my JavaScript file is not functioning correctly. Does anyone have any insights into why this might be happening? index.html: <!DOCTYPE html> <html lang="en"> <he ...

A guide on styling JSON key values within HTML

I need help organizing my JSON Document on an HTML page. Here is the JavaScript code I am using: xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // Optionally, here you can update ...

JavaScript is incapable of locating image files

I am encountering Resource Not Found errors for the image files I am attempting to load into var manifest. Despite following the tutorial code closely, I can't seem to identify what is causing this issue... (function () { "use strict"; WinJS.Bin ...

A guide to customizing nested elements in react using styled-components

Currently, I am utilizing styled components to apply styles to a child element inside a div using nested css. For a demonstration, you can view my example here const customStyles = theme => ({ root: { ...theme.typography.button, background ...

What are the methods for choosing various boxes using the UP/DOWN/RIGHT/LEFT arrow keys?

This code snippet displays a 3x3 matrix where boxes can be hovered over and selected. The goal is to navigate around with keys and select boxes using ENTER. Can anyone provide guidance on how to achieve this functionality? <link rel="stylesheet" href ...

CSS <ul> <li> spacing issue in Internet Explorer 7

My CSS <ul> <li> nested menu is functioning perfectly in IE 8 and Firefox, but in IE7 it is creating a small gap between the elements. Here is my CSS: #nav, #nav ul { margin: 0; padding: 0; list-style-type: none; list-style-po ...

Tips for setting up an automated system to check feeds

While I have experience parsing and setting up databases in PHP, I am now faced with the challenge of constantly monitoring an XML feed for a specific string within one of the tags. Each time this string is detected, I need to add the entire XML item (incl ...

Tips for displaying images dynamically in HTML using AngularJS

src={{logo}} var logo = 'localhost:3000/modules/images/default.png' I'm trying to display the image path dynamically, but it's not showing up in the HTML. Do I need to use quotes for src? Can someone please assist me with this issue? ...

Positioning elements next to each other in jQuery on mouse over - while also addressing scrolling issues in a div

After tinkering with this interesting concept of mouseover combined with absolute positioning divs on a jsFiddle, I encountered some unexpected results. The code was inspired by a stackoverflow thread on positioning one element relative to another using j ...

Styling the navigation bar using CSS

Currently working on establishing a top menu bar similar to StackOverflow, but with a fixed position for my webpage. Check out the JSFIDDLE Demo here Encountering extra space on the left and top of the menu bar. Seeking advice on how to eliminate this ex ...

Show validation error messages for radio buttons alongside images in a single row

Within a div, I have placed three radio buttons with images inline. My goal is to show a validation message using bootstrap when the submit button is clicked and there is no user input. I attempted to add another div after the radio buttons with the class ...

different ways to dynamically increase CSS ID in PHP

Is there a way to dynamically increment my CSS ID using PHP? foreach ($query_cat->result() as $row_cat) { $row_cat_id = $row_cat->id; echo '<div class="product-wrapper">'; echo '<div id="product-header' . $r ...

Utilizing Vue CSS variables as inline styles

Incorporating CSS variables in my component has allowed me to dynamically set the width of a div based on computed data within the setup() setup(props) { const progressBar = PositionService.getProgressBar(props.position); const progressWidth = `${p ...

Continuous loop of images displayed in a slideshow (HTML/JavaScript)

Greetings everyone, I am currently working on creating an endless loop slideshow of images for my website. Despite researching several resources, I am still struggling to get the code right. The issue I am facing is that only the image set in the HTML code ...

What steps are necessary to activate javascript in HTML for WebView?

I recently discovered that when my HTML/JavaScript site is visited via an Android webview, JavaScript is disabled by default. This causes a pricing list on my page to not display properly because it requires a JavaScript class to be added for it to open. I ...

The full screen menu is exclusively displayed in the navigation bar

My HTML and CSS code is causing an issue where the full-screen menu only appears in the nav bar. This problem seems to be specific to Safari. To solve the issue, I need to remove the following code: .nav { position: fixed; } However, I still ...

Do elements containing {visibility:hidden} properties exist within the HTML DOM structure?

Do HTML elements that have the css property visibility:hidden still exist within the DOM tree? ...

Example of a chat server code using NodeJS

I'm looking to add a chat module to my web application. After searching on , I found several chat modules but none of them have clear examples on how to implement them in my project. Can someone share a tutorial that is based on existing NodeJS modul ...

I am experiencing an issue with setting the border to none using .navbar-toggler

I'm currently utilizing bootstrap 5, and I've encountered an issue with setting the border and outline to none in my CSS file. Specifically, when I apply these properties to the nav-toggler class, it seems to have no effect. .menu-bar .navbar- ...