Is there a way to adjust the height of a span element without causing the page to

I recently created an animation featuring a starfield effect using small, rotating radial gradients.

However, there is a noticeable ending point when the gradients stop rotating. I found that increasing the background height solves this issue, but it also increases the overall page height.

Is there a method to increase the background height while keeping it centered on the page?

You can view the codepen for reference: https://codepen.io/twanmulder/pen/GNLRWo

<!doctype html>
<html>
<head></head>
<body>
<div class="starfield">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</body>
<html>

Answer №1

Applying 'position: absolute' to '.starfield' and 'overflow: hidden' to 'body' (or its parent).</p>

<p><div>
<div>
<pre class="snippet-code-css lang-css"><code>body, html {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}

body {
  overflow: hidden;
}

.starfield {
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-animation: fadein 15s; /* Safari, Chrome and Opera > 12.1 */
     -moz-animation: fadein 15s; /* Firefox < 16 */
      -ms-animation: fadein 15s; /* Internet Explorer */
       -o-animation: fadein 15s; /* Opera < 12.1 */
          animation: fadein 15s;
}

.starfield > * {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
}

.starfield > * {
  background-size: 200px 200px;
  background-image: radial-gradient(2px 2px at 40px 60px, #ccc, rgba(0,0,0,0)),
   radial-gradient(2px 2px at 20px 50px, #ddd, rgba(0,0,0,0)),
   radial-gradient(2px 2px at 30px 100px, #eee, rgba(0,0,0,0)),
   radial-gradient(2px 2px at 40px 60px, #fff, rgba(0,0,0,0)),
   radial-gradient(2px 2px at 110px 90px, #ccc, rgba(0,0,0,0)),
   radial-gradient(2px 2px at 190px 150px, #ddd, rgba(0,0,0,0));
  background-repeat: repeat;
}

.starfield > * {
  transform-origin: 50% 50%;
  animation-name: starfieldRotate;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  }

  .starfield > *:nth-child(1){
    animation-duration: 25s;
    animation-delay: -15;
  }
  .starfield > *:nth-child(2){
    animation-duration: 35s;
    animation-delay: -50s;
  }
  .starfield > *:nth-child(3){
    animation-duration: 50s;
  }
  .starfield > *:nth-child(4){
    animation-duration: 70s;
  }
  .starfield > *:nth-child(5){
    animation-duration: 120s;
  }

@keyframes starfieldRotate {
  from {transform:rotate(0deg);}
  to {transform: rotate(360deg);}
}
<div class="starfield">
  <span></span>
  <span></span>
  <span></span>
  <span></span>
</div>

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

Achieving Title Alignment in PDF Export with Balkan OrgChartJS

function preview() { /*centerElement();*/ let fileNameWithTitle = MyTitle.replace(/\s+/g, '_'); let PdfTitle = "<center>" + MyTitle + "</center>"; OrgChart.pdfPrevUI.show(chart, { forma ...

Enhance your JQuery UI autocomplete feature by including images and multiple fields for a more interactive user experience

I am looking to incorporate Autocomplete functionality that will showcase names and avatars similar to the Facebook autocomplete feature. In a recent post Jquery UI autocomplete - images IN the results overlay, not outside like the demo and in the provide ...

Fade-in loader with centered placement on the full page

As a newcomer to programming, I wanted to implement a loader that displays a centered loading animation when the page loads or refreshes. The animation should gray out and fade the entire page until it fully loads. I've managed to get everything else ...

Attempting to extract URLs, month and day details from a table with Selenium Webdriver in Python is resulting in an error indicating that the web element does not

My current task involves extracting links, date, and month from a webpage containing 3 tables. I am particularly interested in retrieving the date and month associated with valid links. You can access the website here: I aim to store the date (e.g., 07 J ...

Implementing PHP logic for adding a class to an HTML tag

I have a PHP file that handles the sending of my form. Everything is functioning correctly, but I need to make a small modification. When the message is successfully sent, I want PHP to dynamically add the "active" class to a specific div in my HTML. This ...

Update Table Row Background Color in Separate Table by Clicking Button Using JQuery

Two tables are involved in this scenario - one that receives dynamically added rows, and another that stores the data to be included. The illustration above displays these tables. Upon clicking the Edit button, the information from the selected row in Tab ...

Activate the radio button upon page load in angularjs

<div class="form-group" style="margin-top: 20px;" ng-repeat="row in skuDetails"> <label class="checkbox-inline"> <input type="radio" name="amount_{{$index}}" value="amount" ng-model="row.amount" ng-checked="row.reductionAmount != &apos ...

The issue with CORS is preventing the AJAX POST request from reaching the Express.js server, even with body-parser configured

Recently, I have been trying to send an AJAX POST request from my HTML page that is hosted on an Apache server. The goal of this request is to post a filename to an express.js server in order to perform some operations with another node. To facilitate this ...

Trouble aligning Material UI data-table columns (table head) to center in React

I have a data table where I declare rows and columns as simple variables, making it difficult to style them using 'style={{textAlign: center}}'. I tried adding a CSS file, but it did not work with the Material UI table. I am unsure of how to proc ...

Arrange 6 columns with equal width using Flexbox styling

Although I'm new to Flexbox, I decided to use it to create a responsive navigational menu consisting of 6 columns. However, I encountered an issue where the menu stretches to 100% of the screen but the button widths are not equal. Is there a way to en ...

Sending numerous web service requests from a single HTML page

My current challenge involves submitting three separate forms on a single page. I have encountered an obstacle while attempting to verify a mobile number in the first form, and then utilize that verified mobile number for final form submission. I initiall ...

The smooth scrolling effect I had programmed suddenly came to a halt

I have a simple jQuery script that allows for smooth navigation through a website using animated scrolling. jQuery(".main_menu li a").click(function() { var href = jQuery(this).attr('href'); if(jQuery(this).html() == 'Home') ...

JS Plugin Loading Problem

What combination of libraries/frameworks would work best for optimizing performance in an HTML5/CSS3/JS app with moving elements? I have done some research, but I am venturing into unfamiliar territory when it comes to performance. Are there key principles ...

Ways to optimize image focus on a webpage

Upon loading the page, I desire for my image to be automatically focused. Unfortunately, setting the tabindex parameter has not produced the desired outcome. This is likely due to the fact that there are multiple angular2 header components with defined t ...

The Navbar is not displaying the React Bootstrap 4 CSS module as intended

Having some trouble changing the color of my navbar. Is there a step I might be missing? Here's the component I'm trying to render: import React from 'react'; import { Nav, Navbar } from 'react-bootstrap'; import styles from ...

Experience the seamless transition of new CSS animations

I designed a basic HTML game where a moving box disappears when clicked on. However, the animation that follows does not originate from the click location but rather from the original position. I believe the remove @keyframes at 0% should be based on the ...

Encountering the error message "Cannot GET /" in a NodeJS Express

I've been experimenting with various approaches to resolve this issue, ranging from app.use(express.static(__dirname + "public")) to res.render. It seems to function correctly in my terminal environment but fails when I try to access it locally. Can a ...

Is there a way to dynamically adjust the position of a canvas element using CSS?

After coding in React, I am facing an issue with the canvas element. When I use a mouse-click to adjust the position and change 3 style properties, everything seems fine until I refresh the page. Upon refreshing, I retrieve the canvas elements' positi ...

Using jQuery to duplicate a div multiple times when scrolling

I'm looking for a way to continuously duplicate the contents of a div as I scroll, creating the illusion of an infinitely scrolling page. My current markup looks like this and you can also find a working example in this fiddle https://jsfiddle.net/guh ...

jQuery Accordian malfunctioning for all elements except the first one in the list

Trying to implement an accordion feature that can be utilized across the entire website. The current logic seems to be partially functional... When I click on any of the accordions, it should open by adding a 'show' class, but this only works for ...