I am having trouble with my fullscreen background not functioning properly

My header is not displaying as a full-screen background, even though the code works on other sites I've built. Can someone please help me figure out what's going wrong?

The code is identical to what I have used successfully on other websites.

Below is the HTML5 and CSS3 code snippet:

body {
  margin: 0px;
  padding: 0px;
  font-family: roboto;
}

header {
  background: url('./pics/bg1.jpg') 50% 50% no-repeat;
  width: 100%;
  height: 100%;
  background-size: cover;
}
<!DOCTYPE html>
<html>

<head>
  <title>Welcome | SoundNet</title>
  <meta name="theme-color" content="#6699ff">
  <!--Meta-->
  <meta charset="utf-8">
  <meta name="keywords" content="">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-capable=yes">
  <!--Js-->
  <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
  <!--Link-->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300">
  <link rel="stylesheet" href="./css/main.css">
</head>

<body>
  <header>
    <div class="menu">
      <ul>
        <li><a href="#">Categories</a></li>
        <li><a href="#">Playlists</a></li>
        <li><a href="#">Login</a></li>
      </ul>
    </div>
    <div class="logo">
      <span class="border-n">N</span>ESTA
      <div class="button">
        Sign Up
      </div>
    </div>
  </header>
  <section>
    <div class="party">
      <h3>Get the party started</h3>
      <p></p>
    </div>
  </section>
</body>

</html>

[Edit: Added snippet without image temporarily.]

Answer №1

Establish a height for the body. When set to 100% height and width, it will inherit its parent's dimensions.

If the body element does not have defined width and height properties, setting the header to 100% height and width will not have any impact.

Example Code Snippet

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

header {
  height: 100%;
  width: 100%;

  background: url('https://htmlcolorcodes.com/assets/images/html-color-codes-color-tutorials-hero-00e10b1f.jpg');
  background-repeat: no-repeat;
  background-size: cover;
}
<header></header>

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

Challenges with Knockout.js Virtual Elements in Different Environments

I am facing a peculiar issue where a virtual knockout template fails to bind correctly when accessed remotely, yet functions perfectly when viewed locally. You can find the problematic page here: Here is the template I am using: <ul> <!-- k ...

The font cannot be located by font-face: file not found

I am a beginner in CSS and want to incorporate the fonts poppins and open-sans in doxygen. Here is my font-face code for Open_Sans: @font-face { font-family: 'Open_Sans'; src: url('fonts\Open_Sans\OpenSans-Regular.ttf& ...

The onchange() function for a multi-checkbox dropdown is failing to work as

Issue with Multiple Drop Down Checkbox Functionality: The first parameter is always received as undefined, and the onchange event only captures the value of the first checkbox selected. <select name="multicheckbox[]" multiple="multiple" class="4colacti ...

Create a login <div> that appears to float effortlessly on the screen

Seeking assistance in creating a login div similar to the one on ups.com. Upon clicking the login button on www.ups.com, a floating login div appears. How can I generate a similar div? Any help would be greatly appreciated. Thank you. ...

I'm experimenting with using jQuery toggle to switch between text and images on my webpage

I attempted to use jquery "toggle" in order to hide the div containing text and display an image instead, and vice versa. However, when I click on the button, it does not work as expected. The button is from a bootstrap example - could that be the source o ...

I would like to retrieve my data using my personal API and have them displayed as checkboxes

https://i.sstatic.net/qPSqe.jpgHere is an excerpt of the progress I have made main.html (it's actually a form) <div class="form-group form-check-inline"> <input class="form-check-input" type="radio" name=& ...

Customize Your Contact Form in Wordpress with a Stylish 2-Column Layout

Hey there, I've encountered a little problem with my website. My website is built on Wordpress and uses Contact Form 7, which has been heavily customized with CSS. While it looks great on desktop, the email field appears too small on mobile devices. I ...

Why does IE make elements disappear when rotated 90 degrees in CSS3?

Why is Image 2 not visible in IE when transformed 90 degrees with some perspective? It works fine in other browsers, but IE always keeps you guessing for hours for no reason. Html : <body> <div class="scene"> <div cl ...

What is causing concatenated string class names to fail in Tailwind CSS?

Whenever I find myself needing to style my React elements, I end up using the style attribute instead of className. None of the examples I've come across seem to apply styles that fit my specific needs. Can you shed some light on why this happens and ...

Adjust the positioning of an HTML element in relation to another to prevent elements from moving erratically

Currently, I am working on a website where I have implemented some javascript to achieve a 'typewriter' effect for the prominent middle-centered text displayed below. The script is designed to animate the text by typing it letter by letter in a f ...

Safari may only provide audio without playing videos

When using Safari on Mac/iOS, I encountered a problem where the video would not play but only the sound could be heard. Additionally, only the first frame of the video was visible. Strangely, switching to another window or minimizing the browser seemed to ...

Can we leverage Angular service styles in scss?

I am working on a change-color.service.ts file that contains the following code snippet: public defaultStyles = { firstDesignBackgroundColor: '#a31329', firstDesignFontColor: '#ffffff', secondDesignBackgroundColor: '#d1 ...

In Angular 16, allow only the row that corresponds to the clicked EDIT button to remain enabled, while disabling

Exploring Angular and seeking guidance on a specific task. I currently have a table structured like this: https://i.stack.imgur.com/0u5GX.png This code is used to populate the table: <tbody> <tr *ngFor="let cus of customers;" [ngClass ...

Issues with Angular ng-click event activation on dialog box button

I have encountered an issue while creating a dialog pop up on my website. When I click a button that is meant to trigger an event and close the dialog, the dialog fails to close. Here is the JavaScript code for the button... $scope.alert = function () { ...

Is it feasible to utilize the translate function twice on a single element?

Using Javascript, I successfully translated a circle from the center of the canvas to the upper left. Now, my aim is to create a function that randomly selects coordinates within the canvas and translates the object accordingly. However, I'm encounter ...

Guide to applying conditional styling to Material-UI TextField

After creating a custom MUI TextField, I implemented the following styling: const CustomDisableInput = styled(TextField)(() => ({ ".MuiInputBase-input.Mui-disabled": { WebkitTextFillColor: "#000", color: "#00 ...

Angular-Components Enhanced with Flexbox Styling

Currently in my angular project, I have a basic header, main, footer structure and I want to transform the main-component into a flex-box so that all components are arranged horizontally with equal width. Moreover, I aim to switch the flex-direction to col ...

Design a clickable div element embedded within an interactive article using HTML5

Currently, I am facing an issue with placing clickable div elements inside an article tag in HTML5. The problem is that when I try to click the divs, it registers as a click on the article itself. Below is an example of my code: HTML: <article id=&apo ...

Using the CSS trick of First-of-type and Last-of-type can result in shortened rounded edges when viewed in IE11

When using the radio+label trick to style radio buttons, a peculiar issue arises in Internet Explorer 11 (IE11). The first and last buttons in each set appear to have their bottom parts cut off or shortened, depending on the background displayed. Removing ...

find the text that is not encompassed by a particular html tag

After coming across this inquiry, I am curious about how one can detect text that is not within a particular HTML tag. desired text: "targetstring" excluding the script HTML tag <div> <h1>targetstring</h1> <= should be detected ...