I can't seem to figure out why my container is not centered on the screen, despite setting the margins (left and right) to auto

Hey there, I'm a beginner in programming and currently experimenting with the CSS vertical text slide animator feature. However, when the animation runs smoothly, I noticed that the text appears disproportionate and not properly centered on the screen, despite setting margins (right & left) to auto.

@keyframes animate{
  0%,100%{
    top:0;
  }
  20%{
    top:0px;
  }  
  25%{
    top:-50px;
  }
  45%{
    top:-50px;
  }
  50%{
    top:-100px;
  }
  70%{
    top:-100px;
  }
  75%{
    top:-150px;
  }
  95%{
    top:-150px;
  }
}
<div class="container " style="margin-left: auto; margin-right:auto">
      <h1 class="display-4 w3-center w3-animate-right" >Hi I'm Raffiel</h1>
      <div class="outer " style="display: block; position:relative;">
        <h1 style="font-size: 45px ;">I am, &nbsp;
        <div class="inner" style="position:absolute; border:0px solid #ddd; height:50px; line-height:50px; font-size:45px; text-transform:uppercase; overflow:hidden; display:inline-block; text-align: left;  font-weight: 400;">
          <span style="animation:animate 10s ease infinite; position:relative;color:#e58e26; text-align: left;">
            Graphic Designer<br>
            Digital Marketer<br>
            Video Editor<br>
            Web Designer<br>
          </span>
        </div>
          </h1>
      </div>
    </div>

This is strong text!

Answer №1

Essentially, the inclusion of position:relative was necessary for the element to occupy "space" and be centered using text-align:center. However, further adjustments are still required for this example to be perfect.

@keyframes animate {
  0%,
  100% {
    top: 0;
  }
  20% {
    top: 0px;
  }
  25% {
    top: -50px;
  }
  45% {
    top: -50px;
  }
  50% {
    top: -100px;
  }
  70% {
    top: -100px;
  }
  75% {
    top: -150px;
  }
  95% {
    top: -150px;
  }
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3b1bcbca7a0a7a1b2a393e6fde1fde3">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">

<div class="container" style="text-align:center">
  <h1 class="display-4 w3-center w3-animate-right">Hello, I'm Raffiel</h1>
  <div class="outer">
    <h1 style="font-size: 45px ;height:50px; line-height:50px ">I am,
      <div class="inner" style="position:relative; border:0px solid #ddd; height:45px; line-height 45px; font-size:45px; text-transform:uppercase; overflow:hidden; display:inline-block; text-align: left;  font-weight: 400; ">
        <span style="animation:animate 10s ease infinite; position:relative;color:#e58e26; ">
            Graphic Designer<br>
            Digital Marketer<br>
            Video Editor<br>
            Web Designer<br>
          </span>
      </div>
    </h1>
  </div>
</div>

Answer №2

give this a shot

@keyframes animate{
  0%,100%{
    top:0;
  }
  20%{
    top:0px;
  }  
  25%{
    top:-50px;
  }
  45%{
    top:-50px;
  }
  50%{
    top:-100px;
  }
  70%{
    top:-100px;
  }
  75%{
    top:-150px;
  }
  95%{
    top:-150px;
  }
}
<div class="container " style=" width:100%; margin: auto;">
      <h1 class="display-4 w3-center w3-animate-right" style="text-align:center;" >Hey I'm Raffiel</h1>
      <div class="outer " style="display: block; text-align:center;">
        <h1 style="font-size: 45px;">I am,
        <div class="inner" style=" border:0px solid #ddd; height:50px; line-height:50px; font-size:45px; text-transform:uppercase; overflow:hidden; display:inline-block;  text-align:left; font-weight: 400;">
          <span style="animation:animate 10s ease infinite; position:relative;color:#e58e26; ">
            Artist<br>
            Musician<br>
            Photographer<br>
            Writer<br>
          </span>
        </div>
          </h1>
      </div>
    </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

Extracting multiline value from a textarea using JavaScript

I'm trying to extract a multiline value from a textarea using JavaScript or jQuery and store it in a cookie. Below is the code snippet I am using: HTML: <textarea id="cont" cols="72" rows="15"> JavaScript: var txt = $('#cont').val( ...

Django causing CSS issues following the utilization of an if statement

I have been working on adding a dropdown list to my navbar, which I created using Bootstrap. However, whenever I place the dropdown menu inside an if statement for looping categories into a list, it seems to be breaking the CSS. Check out the navbar witho ...

Contrasting box-shadow behavior observed in Chrome versus Firefox

I'm working on a project and aiming to achieve this design: https://i.stack.imgur.com/YflaU.png To test it out, I created a sample page with the following code: p { display: inline; background-color: yellow; box-shadow: 10px 0px 0px red, -1 ...

Changing font color of a selected item in Material-UI's textview

I have a select textview in my react app and I am wondering how to change the font color after selecting an item from this textview. <div> <TextField id="standard-select-currency" select fullWidth l ...

Employing jQuery, how can one assign attributes to appended HTML and store them

So, I am currently working on a backend page for managing a blog. This page allows users to create, edit, and delete articles. When the user clicks the "edit" button for a specific article named 'foo', the following actions are performed: The ...

Passing Data Between Blazor App Pages Using .NET Core

Recently, I began learning how to create websites using the Blazor template. I'm having trouble figuring out how to pass data from one page to another. It's quite different compared to .NET CORE MVC web applications and I haven't been able t ...

Exploring the images in a continuous loop

Looking to create a unique image looping effect using HTML, CSS, and Jquery/Javascript. The concept is to display several images on one page that do not move, but loop through them one at a time while displaying text above the current image. For example, ...

Hide, show, toggle, or empty elements using jQuery

I am having trouble getting this jQuery code to function properly. Within a div, there is a paragraph that I want to hide when a specific button is clicked and show when another button is clicked. Check out the code here $("#details").on("c ...

Fixing a menu hover appearance

I recently encountered a small issue with the menu on my website. When hovering over a menu item, a sub-menu should appear. However, there seems to be a slight misalignment where the submenu appears a few pixels below the actual menu item. Check out the w ...

Form-check radio buttons within the form-check-inline class of Bootstrap 4.1.1

I am attempting to showcase a radio button as an inline option. According to the Bootstrap 4.1.1 documentation, the example code is: <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="inlineRadioOption ...

The functionality of dropdown menus in the Bootstrap 5 navbar is currently experiencing issues

I recently updated my Bootstrap from v5.2.2 to v5.2.3 and now the dropdown menus in my navbar are not working properly. They do not drop down as they should, instead, they remain stationary. Can someone please help me figure out what I am doing wrong? & ...

Leverage AJAX variables directly within the HTML page

In my application, I have incorporated an Input type="date" field to capture date values from users. However, I need to send the value of the date as "sdate" in the URL used in the action method, as illustrated below. My goal is to post the value of the In ...

Guide to utilizing a download link for file retrieval in Python

I'm currently working on creating a script that can automatically download specific files from webpages and save them to designated folders. For the most part, I've been successful in achieving this using Python, Selenium, and FirefoxPreferences ...

When resizing the window in IE8, the function DIV offsetWidth/Width/innerWidth returns a value of zero

My page is filled with many elements, one of which is the following DIV: <div id="root"> .................. <div id="child1"> ............. </div> <div id="child2"> ............... </div> & ...

Arranging items in a vertical column using Bootstrap styling

I am facing a particular issue: The initial design is displayed in Picture 1: I am using Bootstrap 5 as my CSS framework. I attempted to utilize the pre-built columns feature, but so far, I have not been able to find a solution and am currently strugglin ...

BS grid malfunctioning in a non-uniform manner

When a division in the advantage grid is clicked, the card body of another division collapses. However, this does not occur in the disadvantage grid. Clicking on one section in the disadvantage grid does not collapse another section as it does in the advan ...

What is the best way to position the header at the top and the footer at the bottom of the page, with the main content in between using

Recently, I started using Bootstrap and incorporated Bootstrap 5.3 into this HTML page. My goal is to align the header at the top, footer at the bottom, and adjust the size of the main content in between. Here's the code I attempted: <!DOCTYPE html ...

What is the best way to center my dropdown menu on the page?

Discover my exclusive menu by visiting this link. For those who are curious about the source code, here's the HTML snippet: <div id='menu-container'> <ul id='menu' class="menu"> <li class='active'>& ...

Get the div to occupy the rest of the available height

I am facing a challenge with two divs on my webpage. The bottom one contains content that expands the highest. The page is set to 100% height and width using the CSS property position: absolute. <style> body, html { height:100%, width:100% } ...

The order of event handlers in jQuery

I am currently setting up event binding for a text element dynamically. Take a look at the following code snippet: <input type="text" id="myTxt" /> <script type="text/javascript"> function attachEvent1(element){ element.keyup(func ...