Text in jQuery is only centered on lines that come after the first line

Looking to create a quiz where clicking the Begin button triggers a jQuery animation, displaying text. The challenge arises when the centered text shifts alignment if it spans multiple lines during the animation.

The issue is ensuring that even single-line text remains centered throughout the animation. How can this code be modified to maintain centering regardless of text length?

HTML

<!DOCTYPE html>
<html>
    <head>
        <link href='http://fonts.googleapis.com/css?family=Indie+Flower'     rel='stylesheet' type='text/css'>
        <link rel="stylesheet" type="text/css" href="50.css">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script>
         $(document).ready(function(){
            $("button").click(function(){
                var div = $("#tgemp");
                startAnimation();
                function startAnimation(){
                div.animate({height: "100%", width: "100%"}, 3000, "swing");
                div.css("background-color", "#99FF66");
        }
        document.getElementById("tt").style.opacity = "1";
        });
        });
        </script>
    </head>
    <div id = "tgemp">
        <p id = "tt"> A walk on the beach may lead to contact with sand</p>
    </div>
    <body>
        <h1>50 States Quiz</h1>
        <div id="firstDiv" align="center"> 
            <h2> Can you name all 50 states? </h2>
            <p id = "timer"> 5:00 </p>
            <button type="button" id = "time" onclick="Begin();"> Begin </button><br/><br/><br/><br/>

            <input type="text"  id = "tb" onInput="Verify()" enabled></input><br/><br/><br/>
        </div><br/>
    </body>
    <center><img src="us.png" height = '50%' id = "img"></center>
</html>

CSS

body{
background-color: #ADD8E6;
background: -webkit-linear-gradient(left, rgba(255,90,90,1),rgba(114,188,212,1));
background: -o-linear-gradient(right, rgba(255,90,90,1),rgba(114,188,212,1));
background: -moz-linear-gradient(right, rgba(255,90,90,1),rgba(114,188,212,1));
background: linear-gradient(to right, rgba(255,90,90,1),rgba(114,188,212,1));
}

h1,h2,#timer{
font-family: 'Indie Flower',serif;
text-align: center;
color: white;
font-size: 325%;
}

h2,#timer{
font-size: 200%;
}

#time {
background: #65a9d7;
border: solid 0px #1e90ff;
border-radius: 50px; 
-moz-border-radius: 50px; 
-webkit-border-radius: 50px; 
color: #ffffff;
font-size: 130%;
font-family: 'Indie Flower',serif;
padding: 5px 15px;
}

#time:hover {
background: #c42f2f;
}

#time:active {
background: #FF9200;

border: solid 0px #1e90ff;
border-radius: 50px; 
-moz-border-radius: 50px; 
-webkit-border-radius: 50px;
}

#time:focus{
outline:0 !important;
}

#tb {
background-color: #ADD8E6;
background: -webkit-linear-gradient(right, rgba(255,90,90,1),rgba(114,188,212,1));
background: -o-linear-gradient(left, rgba(255,90,90,1),rgba(114,188,212,1));
background: -moz-linear-gradient(left, rgba(255,90,90,1),rgba(114,188,212,1));
background: linear-gradient(to left, rgba(255,90,90,1),rgba(114,188,212,1));
border:3px solid #FF9200;
border-radius:10px;
height: 30px;
width: 200px;
text-align:center;
font-family: 'Indie Flower',serif;
color: white;
font-size: 125%;
outline:0 !important;
}

#tgemp{
font-family: 'Indie Flower',serif;
color: #99FF66;
width:0px;
height:0px;
position:absolute;
left:0px;
top:0px;
background-color:red;

}

#tt{
font-family: 'Indie Flower',serif;
color: white;
opacity:0;
position:absolute;
font-size: 400%;
text-align: center;
}

#tt:after{
  content: "";
  display: inline-block;
  width: 100%;
}

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

Can you explain the functionality of the JavaScript code in the index.html file within webpack's react-scripts?

I have been experimenting with dynamically loading a React component into another application that is also a simple React app. However, I am facing challenges getting the index.js file to run properly. While referencing this article for guidance, I notice ...

Tips on converting an array list to JSON format

I am attempting to extract the JSON object from an array list arrayList [ 0: {name: "01", value: "3424234234"} 1: {name: "17", value: "26021734"} 2: {name: "10", value: "435345"} 3: {name: "21", value: "3453"}] The array above has been converted to JSO ...

The Angular 9 custom directive is malfunctioning on mobile devices

I recently created a custom directive in Angular 9 that allows users to input only digits and one decimal point. While the directive works perfectly on desktop, it seems not to function at all on mobile devices - almost as if it doesn't exist within t ...

ReactJS how to prevent accordion from collapsing automatically

My custom accordion layout for the features needed in the site I am building is not working well with Jquery. How can I modify it to collapse properly? Specifically, I want it so that when I open number 2, number 1 will automatically close. I've trie ...

The property 'label' is not found in the 'string' type in Typescript

Below is the code snippet I am using: interface State { resourceGroup: QuickPickItem | string; } setEvent(state.resourceGroup?.label).catch(err => console.error(err)); When executing this code, I encountered the following error messa ...

Best practices for utilizing JSON data to maximize its value

When using node.js version 6.10 console.log("retrieved data1 " + body); // returns: retrieved data1 "{'response' : 'Not latest version of file, update not performed'}" I am attempting to extract the Not latest version of file, update ...

How can CSS be effectively handled across master pages, content pages, and user controls?

When working on a web project that includes content pages, master pages, and user controls, what are the best practices for writing CSS for each of these elements? Should it be included in the page itself, or in a separate file? Is it better to have a sepa ...

Replace .Mui-disabled (or any other pseudo-classes/states) in the MUI v4.1.X theme with custom styling

How can I globally override the default grey background color for disabled items in Material-UI v4.1.x? I know how to do it for specific components like MuiMenuItem, but I'd prefer a solution that doesn't require me to add overrides for each indi ...

Populate dropdown list dynamically in Codeigniter using AJAX and jQuery

Although this question may appear to be a duplicate, none of the other answers provided have solved my issue. My query pertains to populating a dropdown using ajax/jquery. While I can successfully send and receive data in JSON format, it doesn't seem ...

Is there a way for me to determine the dimensions of the webcam display?

How do I determine the width and height of the camera in order to utilize it on a canvas while preserving proportions? I am attempting to ascertain the dimensions of the camera so that I can use them on a canvas. On this canvas, I plan to display live vid ...

ESLint error: EROFS read-only does not correspond to any directory

Can anyone help me with this issue? I am experiencing a problem when using Linux dual boot, but everything works fine when I use Windows. ERROR in [eslint] EROFS: read-only file system, open '/media/naufal/6878124278121004/Refactory/Skill-Test-Re ...

Highlight dates in Vue.js that are overdue using a date filter

Currently, I have a Vue filter set up to display dates in a visually appealing way. However, I am looking to enhance the filter by adding a feature that would highlight dates in red if they are overdue (meaning the date is earlier than the current date). I ...

Using JQuery to delete an item by clicking on the delete button and then clicking on the item to remove it

I am currently using jQuery to dynamically create items on an HTML canvas for users to drag around and create drawings in a style similar to Microsoft Visio. However, I am struggling with how to remove these items once they have been created. While I know ...

The conditional statement for ajax is malfunctioning

I am encountering an issue with some ajax coding. The if condition is not working as expected - whenever the program runs, only the else statement gets executed even when the if statement should be satisfied. <script type="text/javascript> funct ...

Exploring the efficiency of different CSS selectors

I am struggling with the following code: HTML: <ul class="list"> <li class="list-item"> item 1 </li> <li class="list-item list-item_active"> Active item </li> <li class="list-item"> item 3 </li> ...

Is there a way to ensure that my footer container maintains the same width as the content when it slides to the left

When I access my testsite at If I click on the top left icon (filter), the content and footer slide to the left, revealing that the footer container does not have the same width as the content container due to the scrollbar in the content. What is the so ...

Tips for loading a webpage directly to the center instead of the top position

Is there a way to make the page open at a specific div halfway down the page instead of starting from the top? Here is an example: <div id="d1"> <div id="d2"> <div id="d3"> <div id="d4"> <div id="d5"> <div id="d6"> Do ...

I created an image that can be clicked on, but unfortunately it only functions properly on the

I am currently working on creating an image that can be clicked to cycle through different images all within the same frame. While I have managed to get it to work, I am facing a limitation where it only responds to one click. count = 1; function myF ...

Utilizing Chained Conditions in React JSX

Although the code below is functional and yields the desired outcomes, I can't help but question if there's a better way to do it. { Conditon1?<ChildComponent />:Condition2?<p>Hi</p>:<p>Bye</p> } I'm partic ...

Refreshing material ui select choices based on user input

Just getting started with Reactjs and I need some help. I have a material ui select element that has default values set, and when I click the 'ADD USER' button and submit, I can add new values to the select element. I'm also able to delete o ...