What could be causing my paragraph to shift when an animated expanding header is applied in CSS?

For a school assignment, I am facing an issue where the paragraph is being affected by my CSS animation on the main header title that expands and contracts. My goal is to keep the paragraph in a fixed position without being moved by the header animation (View it in full size)

body {
  background-color: blue;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font: Arial, Helvetica, sans-serif black;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 18px;
  border-radius: 5px;
  border-bottom: solid black;
  border-top: solid black;
  border-left: solid black;
  border-right: solid black;
  background: #09F;
  background: -webkit-linear-gradient(#09F, #9FF);
  background: -o-linear-gradient(#09F, #9FF);
  background: -moz-linear-gradient(#09F, #9FF);
  background: linear-gradient(#09F, #9FF);
}

li {
  float: left;
}

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

li a:hover {
  background-color: #0FC;
}

@keyframes expand {
  0% {
    font-size: 3em;
  }
  50% {
    font-size: 4em;
  }
  100% {
    font-size: 3em;
  }
}

div.header {
  font-family: "Impact";
  font-size: 100px;
  color: white;
  text-align: center;
  text-shadow: 5px 5px black;
  margin-top: 134px;
  margin-bottom: 32px;
  animation-name: expand;
  animation-duration: 1s;
  animation-iteration-count: infinite;
}

div.center-out {
  display: table;
  margin: auto;
}

div.center-in {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}

div.intro {
  text-align: center;
  color: white;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 36px;
}

.button1 {
  background-color: #0CF;
  border: none;
  color: white;
  padding: 15px 32px;
  text-decoration: none;
  font-size: 16px;
  cursor: pointer;
  width: 250px;
  position: absolute;
  top: 75%;
  right: 44%;
}

.b1 {
  text-align: center;
  font-family: Arial, Helvetica, sans-serif;
}

.button1 {
  -webkit-transition-duration: 0.4s;
  /* Safari */
  transition-duration: 0.4s;
}

.button1:hover {
  background-color: #09F;
  color: black;
}

a:visited {
  text-decoration: none;
  color: black;
  font-family: Arial, Helvetica, sans-serif;
}
<!DOCTYPE html>
<html>
<link href="style3.css" type="text/css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Supermercado+One" rel="stylesheet">

<head>
  <title>The How to Draw Homepage</title>
</head>
<ul>
  <li><a href="#home">Home</a></li>
  <li><a href="#Tips">Tips</a></li>
  <li><a href="index.html">Learn</a></li>
  <li><a href="contact.html">Contact</a></li>
</ul>

<body>
  <div class="center-out">
    <div class="header">
      <h1>Learn to Draw!</h1>
    </div>
    <div class="intro">
      <span><p>Welcome to the best place to enhance your drawing skills with helpful techniques!</p></span>
    </div>
  </div>
  <div class="b1">
    <a href="index.html"><button class="button1"><span>Start Drawing!</span></button></a>
  </div>
</body>

</html>

Answer №1

To enhance performance and prevent shifting of surrounding elements, it is recommended to transition/animate the transform property instead of font-size.

body {
  background-color: blue;
}

@keyframes expand {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}

div.header {
  font-family: "Impact";
  font-size: 50px;
  color: white;
  text-align: center;
  text-shadow: 5px 5px black;
  margin-top: 134px;
  margin-bottom: 32px;
  animation-name: expand;
  animation-duration: 1s;
  animation-iteration-count: infinite;
}

div.center-out {
  display: table;
  margin: auto;
}

div.intro {
  text-align: center;
  color: white;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 36px;
}
<div class="center-out">
    <div class="header">
      <h1>Learn to Draw!</h1>
    </div>
    <div class="intro">
      <span><p>Welcome to the greatest and helpful place to learn techniques to improve your drawing skills!</p></span>
    </div>
  </div>
</div>

Answer №2

Include the following directive:

.banner {
  height: 160px;
}

The banner's size will now remain consistent instead of expanding and contracting with your heading.

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

Button malfunctions when attempting to Append

Currently, I am working on a window-oriented application that operates similar to an operating system using jQuery. The issue I am facing is that when a window is clicked, it appends itself to the parent element, appearing on top of all other windows. Howe ...

Managing Image Quality with Unsplash API

How can we ensure high quality images are embedded on the web using Unsplash API or other methods? The image displayed in the example below appears blurry and unclear compared to the original image. Original Image link: Example of embedding the image abo ...

Is there a way to display a caret pointing downwards instead of to the right when clicked to open a sub-menu?

I designed a navigation bar that includes a sub-menu feature. Currently, there is only one member with a caret symbol positioned nearby. When this member is clicked, the sub-menu opens displaying other members. However, the caret remains pointing to the ...

Network plot search box

I have utilized the forceNetwork() function from the networkD3 package to construct a Network of protein mutations. It is then displayed in RStudio's "Viewer" pane. After creating this network, I am able to save it as an HTML file for sharing while r ...

angularjs dropdown - customize selected item appearance

My dilemma involves a list of countries, each with a code and name. When the list is expanded, I aim to show "code + name" (e.g. "+44 United Kingdom"). However, once a country is selected, I only want to display the code ("+44"). Is it achievable using Ang ...

Looking to add a JSON object to the Angular.JS controller's scope

Knowledge of Java Server Pages is not necessary to address the issue at hand; it simply provides context for the challenge I am currently encountering. I am in the process of developing an application in Adobe AEM that utilizes Java Server Pages to displa ...

"Clicking on an anchor tag triggers the appearance of the ngf-select popup as well

I attempted to create a file dropbox using the ngf-select feature. Within the div, I included an a tag for removing a file. However, whenever I click on the a tag, the ngf-select function also activates unexpectedly. See image here. ...

Using Javascript and CSS to Float DIV Elements

Recently, I've been working on a small algorithm that adds a special class to an element when the mouse reaches the halfway point or beyond on the X-axis of the browser. I also have a screenshot that demonstrates where this application will be utiliz ...

The text appears larger than the surrounding 'element'

I've noticed that when I set the font size of a specific p tag to 55px, the actual element containing the font appears smaller than the font itself. As a result, the font ends up overlapping the elements above it. While I can add padding to fix this ...

Browsing HTML Documents with the Click of a Button

After collecting JSON data from a SharePoint list, I am currently in the process of creating an HTML Document. At this point, I have completed approximately 80% of the expected outcome. Due to Cross-Origin Resource Sharing (CORS) restrictions, I have hard ...

Utilize grids to ensure consistency in the width of every <li> element across the browser

Is there a way to make the ul element span the entire width of the webpage regardless of window size? http://jsfiddle.net/32hp1w5p/ ul { grid-column: 1/13; list-style-type: none; display: table; margin: 0 auto; } li { float: left; border: ...

Reaching SVG with CSS

Is it possible to target SVG elements with CSS? In older versions of IE, they display like broken images and I want to hide them using modernizr. I'm looking for a solution like the following... .no-svg object[type=svg] { display:none; } I have be ...

Every time I insert the SVG logo onto the bootstrap navbar, the formatting mysteriously alters

I'm facing an issue with my svg logo on the navbar - half of it is formatted correctly while the other half is not. Additionally, there is a discrepancy in how it appears on Safari and Chrome. I exported this svg file from Adobe Illustrator and incorp ...

Update the div's class according to the video file it is linked to

Is it possible to dynamically show or hide a div depending on the source of a video being played? I have a slideshow of videos running using bigvideo.js and I am looking for a way to toggle the visibility of certain divs based on which video is currently ...

Comparing flex-fill and flex-grow-1 in Bootstrap: Understanding the distinctions

Can you explain to me what sets apart the flex-fill and flex-grow-1 classes in Bootstrap 4+? According to the documentation, flex-fill is defined as: Fill When applied to sibling elements, the .flex-fill class ensures that they occupy widths equal to the ...

The Aframe 'initiatingEvents' feature does not seem to be functioning properly when using a gltf model

I'm attempting to add animation to the movement of a gltf model in A-Frame by clicking on a button. The animation functions properly when the 'startEvents' property is not included, but fails to work once the property is added. Interestingly ...

The translation feature in React does not seem to be functioning properly with SASS

After trying various display settings like flex and block without success, I realized that the transform property was not working as expected. Despite centering elements successfully using other methods, the transform doesn't seem to have any effect o ...

Tips for establishing a fixed point at which divs cease to shrink as the browser size decreases

There are numerous dynamically designed websites where divs or images shrink as the browser size decreases. A great example of this is http://en.wikipedia.org/wiki/Main_Page The div containing the text shrinks proportionally to the browser size until it ...

How can you modify the Bootstrap width to activate the responsive design?

I currently have the following HTML code snippet: <!DOCTYPE html> <html lang="en> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale= ...

I am interested in creating a drop-down menu that opens when clicked, instead of hovering with the mouse, using only CSS and without relying on jquery, javascript,

After creating my own drop down menu, I am looking to make a condition where the list will show after clicking the mouse instead of showing on mouse hover. Is there a CSS property that can achieve this without using jQuery or JS? Here is the source code: ...