Is there a way to correct the functionality of the CSS animation "slide-in" for the #intro element?

As I embark on the journey of creating my very first website, I encountered a challenge with the slide-in and slide-down animations. Everything was working perfectly until I made the decision to set the navigation bar's position as fixed. This change ended up ruining the animation, specifically affecting the slide-in animation of the #intro section. I managed to fix the slide down animation of .welcome-text, but unfortunately, I couldn't find a solution for the slide-in animation of #intro that wouldn't distort other pages. My main aim is for the slide-in animation to smoothly transition without causing any layout disruptions. Below you will find the relevant code snippets.

    //HTML 

        '''<!DOCTYPE html>
        <html lang="en">

        <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Deborah Palm Tree</title>
        <link rel="stylesheet" href="profile.css">
        <link rel="stylesheet" href="work.css">
        <link rel="stylesheet" href="about.css">

        </head>
        <section class="Home" id="#Home">

        <nav class="nav-bar" id="#nav-bar">
            <ul>
                <li><a href="#Home">Home </a></li>
                <li><a href="#Work">Work</a></li>
                <li><a href="#About">About </a></li>
            </ul>
        </nav>

        <body>

            <section id="#Home">
                    <h1 class="welcome-text"> Welcome to my page! </h1>
                <div id="intro" class="page-intro">

                    <a name="Home">
                        <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. A modi veniam 
        repellendus nesciunt
                            nemoquam Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas 
        mollitia placeat
                            perspiciatis
                           ...
                                        necessitatibus incidunt consectetur debitis quisquam assumenda deleniti 
         quam molestias nemo.
                            Perspiciatis aperiam sit fugit provident mollitia. Nostrum, fuga quaerat praesentium excepturi
                            iste impedit co...
                    </a>
                    <a href="" class="btn"> EXPLORE </a>
                </div>
                </section>


        <section class="Work" id="#Work">
        <h2 class="h2-Work"> WORK </h2>
        <a name="Work">
            <p class="p-Work">
               ...
              tent perferendis cumque.
            </p>
        </a>
        </section>

        <section class="About" id="#About">
        <h3 class="h3-About"> ABOUT </h3>
        <a name="About">
            <p class="p-About">
                Lo...
                    velit temporibus sed impedit minima doloremque earum excepturi accusamus culpa vel sit natus dolor velit, hic,
                sapiente ea ut quae. In placeat velit excep...
            </p>
        </a>

        </section>


        <section class="footer" id="#footer">
        <footer>
            &copy Website designed by Deborah Palm Tree.
        </footer>
        </section>

        </body>

        </html> '''



//CSS -The HTML has 3 nav-bar items I set the nav-bar position to fixed and its top to 
zero to ensure the nav-bar is static as I scroll down the page this affected the slide- 

animation of the Home

    ''' * {
        margin: 0;
        padding: 0;
    }

    body {
       ...
      tion ease;
    }

    .p-Work {
        color: antiquewhite;
        text-align: center;
    }

    .p-About {
        color: antiquewhite;
        text-align: center;
    }

    .footer {
        color: antiquewhite;
        background-color: cadetblue;
        min-width: 100%;
    }'''

Answer №1

#intro {
    animation: slide-in 3s forwards;
    transform: translate(-50%);
    position: relative;
    left: 50%;
}



position: relative;

This CSS code is used to center an element within its parent element by adjusting its position using the `left` and `transform` properties.

left: 50%;

The `left: 50%;` rule centers the element horizontally within its parent element.

transform: translate(-50%);

The `transform: translate(-50%);` rule shifts the element's center point from the top left corner to the center of the page, ensuring proper alignment.

I hope this explanation clarifies how these CSS properties work together to center elements on a webpage.

Answer №2

Following the instructions provided, ensure to retain the modifications outlined in my previous answer and implement the following code snippet to fix the navbar position:

nav.nav-bar {
        position: fixed; (<<<< the nav bar will stay at the top of the page)
        top: 0;
        background-color: darkolivegreen;
        min-width: 100%;
        height: 8vh;
        z-index: 5; (<<<<<< the content goes under the nav)
}

Z-index determines the stacking order of elements on a webpage. Higher z-index values bring elements forward above others, as long as they are positioned - as is the case with the fixed position used here.

For point 3), the introductory text should slide in from the left side. The current code appears to handle this animation correctly as modified below:

#intro {
    animation: slide-in 3s forwards;
    transform: translate(-50%);
    position: relative;
    left: 50%;
}

If any issues arise, do not hesitate to inform me :)

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

React text hover image functionality

Just diving into the world of React and attempting to create a cool image popup effect when you hover over text in my project. I could really use some guidance on how to make it function within React, as the logic seems a bit different from plain HTML. Any ...

Retrieving data from a <div> element within an HTML string using jQuery and AJAX

Having trouble extracting a value from a div within an HTML string. Seeking assistance in identifying the issue. I've attempted various methods to retrieve the data, but none seem to work for me. It appears I may be overlooking something crucial. $( ...

Accelerate blinking timer by utilizing CSS3 animations

I'm currently developing a quiz application that includes a timer counting down from 10 seconds to 0 seconds. As the timer reaches closer to 0 seconds, I am looking to implement a feature where my text blinks faster and faster. Additionally, I would l ...

How can I prevent tinymce from stripping out my <link> tag?

I'm having an issue with tinymce. dd<script id="kot-id" src="***insert link here***"></script><div id="kotcalculator"></div><link rel="stylesheet" href="***insert link here***" type="text/css" media="screen" /> It seems ...

Open $_POST in a new tab that has been edited for your convenience

<form method="post" target="_blank" action="battle.php" onsubmit="window.open('battle.php','','width=700,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=0,left=30,top=0');" > < ...

Encountering an error message related to Bootstrap carousel: "Unable to read property 'offsetWidth' of undefined"

Encountering a frustrating error message: "Cannot read property 'offsetWidth' of undefined" when using Bootstrap carousel. Let me share my code with you: <div id="myCarousel" class="carousel slide" > <ul class=& ...

Using footable js will eliminate all form elements within the table

After incorporating the Footable jQuery library to create a responsive table, I encountered an issue with input tags and select boxes being removed by the Footable JavaScript. It turns all these tags into empty <td> elements. <table id="accordi ...

Protect your website's ajax-generated content from being indexed by search engines with these strategies

Recently, Google made an update allowing its crawler to index ajax-generated content on web pages by following specific guidelines. However, my requirement is to ensure that no search engine can crawl my ajax-generated content. So, my question is: What ...

Extract value from child div using JQuery and update text in another section of the page

Here is a fiddle showcasing the concept I am working on: https://jsfiddle.net/wvz9p3e7/1/ The code is written in PHP and involves a loop for cycling through 7 or 8 different garments. My goal is to have the window on the right side of the fiddle display t ...

How to ensure uniform button sizes in an HTML form by setting them all equal to the size

The code snippet provided below demonstrates a basic form with two submit buttons. <form> <input type="submit" value="< Previous"> <input type="submit" value="Next >"> </form> Depending on the value attribute, the bu ...

Achieving 100% height with Flexbox in CSS

In my layout, I have a column on the right with <IndustryList />, and I want everything in the other <div> that contains <ParameterAndPostSearch /> and <SocialPostList /> to extend to the bottom. However, no matter what I try, setti ...

Troubleshooting: Issues with AngularJS Data Binding in HTML Tables

I have been working on code from an online tutorial but unfortunately, it is not functioning properly. I have checked the script, app, and controller but still cannot identify the issue. Any assistance would be greatly appreciated! ...

Show a pop-up notification when the quantity in one set of cells matches the quantity in a different set of cells

Does anyone have a script that can show a popup message when the count of yellow cells matches the count of red cells? Here is a visual representation of what I'm looking for. Any assistance would be greatly appreciated. https://i.sstatic.net/2bJsx.p ...

Styling Radio Buttons with CSS - Customizing the Look of Individual Radio Buttons

How can I customize the appearance of each radio button? This is my attempt at styling them: div.radio-toolbar {width:410px;} .radio-toolbar input[type="radio"] { display:none; } .radio-toolbar label { display:inline-block; background:#FFF; ...

Can you provide instructions on creating a small border at the center of an h1 heading?

What is the best way to create a small border in the center of an h1 text element? ...

Troubleshooting the issue of JavaScript not executing on elements with a specific CSS class

I am attempting to execute a JavaScript function on each element of an ASP.NET page that is assigned a specific CSS Class. Despite my limited knowledge of JavaScript, I am unable to determine why the code is not functioning properly. The CSS Class is being ...

The functionality of changing the checkbox to "checked" by clicking on the span is not

How can I create a toggle button with a checkbox using css and jquery? Clicking on the span representing the toggle button should change the checked property of the checkbox. Currently, the span does not change the property, even though it triggers the c ...

Creating an autofocus feature using Angular 7 upon clicking a button

Within a table in my application, I have text boxes that are initially disabled and then enabled after clicking an edit button. Everything is working smoothly so far, but I am trying to set the autofocus to the first textbox of the first row when the edi ...

After closing a window in GXT, the Element will be removed using RootPanel's get(String id) method

I am working on a GWT project with the GXT framework, and I have an embed tag in my project.html as shown below: <embed type="application/nptta" width=100% height=100% id="testId"></embed> There is a formPanel that will use RootPanel.get("tes ...

Discovering the maximum value in AngularJS using an expression (complete with a bug demonstration)

How can I set a maximum value for an input that can be either a numeric amount or a percentage? Is it possible to use ng-max to set the max value to 100 if the input is a percentage, and leave it blank if it's a numeric amount? I attempted the follo ...