Expansive background with adaptable height dimensions

Is there a way to use Foundation to create a header with a full-width image and responsive height using CSS only, or do I need to use JavaScript for this? Can someone assist me with this?

This is the code from index.html:

<!doctype html>
<html class="no-js" lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Site</title>
    <link rel="stylesheet" href="css/foundation.css">
    <link rel="stylesheet" href="css/app.css">
  </head>
  <body>
    <header id="page-header">
      <div class="row">
        <div class="background" data-interchange="[image/background.jpg, default],
          [image/small-background.jpg, small],
          [image/medium-background.jpg, medium],
          [image/large-background.jpg, large],
          [image/xlarge-background.jpg, xlarge]">
          <h1 class="text-center">
            <img data-interchange="[image/logo.png, (default)],
              [image/small-logo.png, (small)],
              [image/medium-logo.png, (medium)],
              [image/large-logo.png, (large)],
              [image/xlarge-logo.png, (xlarge)]" alt="Logo" />
            <noscript>
              <img src="image/logo.png" alt="Logo" />
            </noscript>
          </h1>
        </div>
      </div>
    </header>
    <section id="page-content">
      <div id="services" class="row">
        <div class="small-12 columns">
          <h2 class="text-center">Title</h2>
          <p>Text here</h2>
        </div>
      </div>
    </section>

    <script src="js/vendor/jquery.js"></script>
    <script src="js/vendor/what-input.js"></script>
    <script src="js/vendor/foundation.js"></script>
    <script src="js/app.js"></script>
  </body>
</html>

Here is the app.css file:

html, body {
  height: 100%;
}

header#page-header {
  height: 100%;
}

header#page-header > div.row {
  height: 100%;
}

header#page-header div.background {
  height: 100%;
  width: 100%;
  background-size: 100% auto;
  background-repeat: no-repeat;
}

header#page-header div.background > h1 {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

And the app.js file contains the following code:

$(document).foundation();

Your assistance is greatly appreciated.

Answer №1

Instead of using height: 100%, consider trying auto

header#main-header div.background {
  height: auto;  // Give this a try
  width: 100%;
  background-size: 100% auto;
  background-repeat: no-repeat;
}

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

How can I prevent query string parameters from being sorted in React Router?

I'm having trouble setting a Route path with a query string using react-router. The issue is that react-router always arranges query params alphabetically, resulting in a sorted query string in the URL. For instance, on a location filter page where I ...

What is the best way to evaluate two values using jQuery?

I need to select them and add a new class. <div class="count_1"> <span class="percentage">10 %</span> </div> <div class="count_2"> <span class="percentage">90 %</span> </div> if (parseInt($(".count_1.per ...

Operating on Javascript Objects with Randomized Keys

Once I retrieve my data from firebase, the result is an object containing multiple child objects. myObj = { "J251525" : { "email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c3823212 ...

Using ES6 classes in Express routes: It is not possible to create the property 'next' on the string '/'

I'm currently working on integrating routes using classes in my express js application controller class User { constructor (){ this.username = 'me'; } getUsername(req,res){ res.json({ 'name& ...

Encountering a TypeError with Arg 1 while trying to execute the save method in jsPDF

I am currently working on a react project with a simple implementation of jsPDF. I am trying to execute the sample 'hello world' code but encountering an error when using the save method: https://i.stack.imgur.com/o4FWh.png My code is straightf ...

Creating dynamic DIV elements in an AngularJS file using data retrieved from a Sql server

I need to dynamically add elements based on data retrieved from a MSSQL server in the specified area: <div id="ApplicationForm" class="tabcontent" style="display:none;"> <div class="tab_section"> ...

"Encountered an error: Unable to access property 'fn' on an undefined object within the Wordpress

I attempted to recreate the steps outlined in this blog post Create A Realistic Self-solving Rubik's Cube With Three.js on a Wordpress page. However, I encountered the following error Uncaught TypeError: Cannot read property 'fn' of undefine ...

html inserting line break using label

I am attempting to dynamically set text to a label using jQuery. However, I am having trouble getting the <br> or \n to create new lines. Instead, all the text displays on the same line and wraps around. If you want to see my code in action, ch ...

Text transitions in a gentle fade effect, appearing and disappearing with each change

I want to create a smooth fade in and out effect for the text within a div when it changes or hides. After researching on Google and Stack Overflow, I found that most solutions involve adding a 'hide' CSS class and toggling it with a custom func ...

jquery plugin causing issues with bootstrap button functionality

Currently, I am utilizing the jQuery form plug-in to post my form in an Ajax way. The post function is functioning perfectly with the default button. However, it seems to encounter issues when I try to use a custom Bootstrap button as shown below. Could so ...

Nesting conditions within partials using Handlebars

Hey there! I'm having an issue with my page layout, here's what it looks like: --- title: Coffee replace: true --- {{> products-list-style}} So, my partial "products-list-style" is like this: {{#if ../replace}}Replace{{else}}Add to Cart{{/i ...

What could be preventing me from exporting and applying my custom JavaScript styles?

This is my primary class import React, { Component } from 'react'; import { withStyles } from '@material-ui/core/styles'; import styles from './FoodStyles'; class Food extends Component { render () { return ( & ...

Is there a way to store image URLs in a fashionable manner?

Hey there! I've been working on creating a HTML page that showcases multiple images. Everything is running smoothly on my localhost, but when I try to access it online, the images take forever to load. Any suggestions on how I can cache image URLs in ...

What is the method for interacting with an embedded alert using SeleniumIDE?

When working with HTML, I came across the following code snippet (it's not from my website): <script> alert('1'); </script> My challenge now is to test this code using Selenium IDE and ensure that the alert will be clicked. How ...

Determine webpage load speed using Javascript and the window.performance.timing method

Utilizing Selenium in C#, I have devised a method to calculate page load times, as demonstrated by the code snippet below: Code: Selenium C# using OpenQA.Selenium; double requestStart = (long)((IJavaScriptExecutor)CTest.Driver).ExecuteScript("return wind ...

Adding data to a defaultContent JSON column in JQuery DataTable using JavaScript

I am working with a dynamic jQuery data table. The final column in my table allows users to delete rows, but I am having trouble passing the itemId value to the specified function within the button's onClick attribute. Here is the code I have tried s ...

Tips for updating the color scheme in your CSS file by making hue adjustments to all colors

I have a CSS file and I am looking to automatically generate multiple color variations of the file by altering the hue, similar to using the "colorize" function in GIMP. I came across a tool that does exactly what I need at , however it does not support t ...

Converting CSS specific to a particular vendor: A step-by-step

Looking for a method to adapt a CSS file containing only -moz-css-property references to include compatibility with Chrome, Safari, and other browsers. Ideally seeking a user-friendly web application that can perform this task seamlessly. ...

What's causing the issue with the rot-corona animation not functioning properly?

I am currently working on a project related to the coronavirus, and I am having trouble with the animation "rot-corona." I need it to rotate 360 degrees every 3 seconds. Please note that Bootstrap 4 is being used in this project. Code /* SCSS */ #rota ...

Pause for a few moments prior to initializing Bootstrap and Angular 2

I am currently developing a space/gravity game using Angular 2, and I am looking to incorporate a splash screen before the main menu component is loaded. I believe that the easiest approach would be to utilize the pre-bootstrapped contents of the index.ht ...