Prevent the row height from fluctuating following the fadeOut() effect

Currently, I am facing an issue with two elements on my page: .start_over_button and .speed_buttons. In CSS, the .start_over_button is set to display: none, and in my JavaScript code, I have it so that when .speed_buttons are clicked, they fade out and the .start_over_button fades in. The problem arises because I am using Bootstrap for positioning my page elements, and due to the differing heights of .start_over_button and .speed_buttons, the page jumps around when the JavaScript function runs, which is quite annoying. I want to ensure that both elements have the same height regardless of the viewport size to prevent this behavior. However, every attempt to set the heights equal in my stylesheet has either had no effect or has not worked as intended. Below is the structure of the div:


    <div class="row thirdRow">
        <a class="start_over_button" href="index.html">
            <button type="button" class="btn btn-default btn-lg col-xs-10 col-xs-offset-1 col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4">
                <span class="glyphicon glyphicon-repeat" aria-hidden="true"></span>
                Start Over
            </button>
        </a>
        
        <div class="speed_buttons">
            <label id="slowText" class="radio-inline col-xs-2 col-xs-offset-3">
                <input id="slow" class="difficulty" type="radio" name="user_options" value="300">
                    Slow
                    <span class="glyphicon glyphicon-cloud" aria-hidden="true"></span>
            </label>

            <label id="medText" class="radio-inline col-xs-2">
                <input id="med" class="difficulty" type="radio" name="user_options" value="150">
                    Med
                    <span class="glyphicon glyphicon-fire" aria-hidden="true"></span>
            </label>
            
            <label id="fastText" class="radio-inline col-xs-2">
                <input id="fast" class="difficulty" type="radio" name="user_options" value="75">
                    Fast
                    <span class="glyphicon glyphicon-flash" aria-hidden="true"></span>
            </label>
        </div>
    </div>

Below is the CSS code snippet:


.start_over_button{
    display: none;
} 

The JavaScript code:


$(".speed_buttons").fadeOut(0, function(){
    $(".start_over_button").fadeIn(0);
});

I am relatively new to coding and have been searching for a solution to this issue for the past couple of days on platforms like W3Schools, Stack Overflow, and API jQuery. Any help or guidance you could provide would be greatly appreciated! Thank you in advance.

Answer №1

If you want to hide an element, consider using visibility:hidden instead of display:none. This way, the element is still technically present in the DOM and takes up space, but it remains invisible to the user.

To learn more about the difference between visibility:hidden and display:none, check out this resource: What is the difference between visibility:hidden and display:none?

Answer №2

To ensure consistent sizing of buttons, encapsulate them in an additional div element and set a fixed height for that container:

<div class="row thirdRow">
  <div class="buttons-container">        
   <!-- Use JavaScript to reload the page on button click. Consider moving this functionality to script.js (href="javascript:location.reload(true)")-->
    <a class="start_over_button" href="index.html">
        <button type="button" class="btn btn-default btn-lg col-xs-10 col-xs-offset-1 col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4">
                <span class="glyphicon glyphicon-repeat" aria-hidden="true"></span>
                Start Over
        </button>
    </a>
    <div class="speed_buttons">
        <label id="slowText" class="radio-inline col-xs-2 col-xs-offset-3">
            <input id="slow" class="difficulty" type="radio" name="user_options" value="300">
                Slow
                <span class="glyphicon glyphicon-cloud" aria-hidden="true"></span>
        </label>
        <label id="medText" class="radio-inline col-xs-2">
            <input id="med" class="difficulty" type="radio" name="user_options" value="150">
                Med
                <span class="glyphicon glyphicon-fire" aria-hidden="true"></span>
        </label>
        <label id="fastText" class="radio-inline col-xs-2">
            <input id="fast" class="difficulty" type="radio" name="user_options" value="75">
                Fast
                <span class="glyphicon glyphicon-flash" aria-hidden="true"></span>
        </label>
    </div>
   </div>
</div>

CSS

.buttons-container {
  height:100px;
}

Adjust the height based on the largest button size for optimal display.

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

"Using jQuery to trigger a click function on elements with the same

Whenever I click the comment link all of the divs are opening but i need that particular only to be opened. HTML: <div> <a href="#" class="ck">comment</a> <div class="cmt"> <input type="text" class="txt"/> ...

Calling ASPX method remotely and receiving undefined data

I'm still fairly new to ASP.NET and web services. I've encountered an issue where I am calling a web service from a *.aspx page, and the web service is returning the correct output. However, when I call the *.aspx method from an external HTML pag ...

The CSS attribute selector is unable to target dynamically appended class names

Utilizing React's CSS animations add-on has been a seamless process, with everything running smoothly when using the provided classnames. .quote-enter { opacity: 0.01; transition: opacity .25s ease-in; } .quote-enter.quote-enter-active { opaci ...

Displaying multiple info windows on a Google Map using React

I'm in the process of developing a Google Maps API using react-google-maps and I want to add multiple markers to display information about cities from around the world in info windows. However, when I click on one marker, all the info windows open at ...

What is the proper way to implement JQuery within a constructor function contained in a JavaScript namespace?

Yesterday I ran into a problem when asking about using JQuery inside a JavaScript constructor function within a namespace. There was a bug in my code that caused me to get the answer to the wrong question. var NS=NS||{}; NS.constructor=function() { t ...

Retrieving data from an HTML webpage using VBA

In my attempt to access the "username" cell from a web page using VBA, I encountered an issue. The HTML code of the page contains multiple elements with the same name, "LOGON_USERID", making it challenging for me to identify and access the correct one. Hi ...

Is there a way to prevent the node modules folder from being uploaded when deploying a React app on Github Pages?

Struggling with the lengthy upload time of my React app on Github Pages. Every attempt to upload the node modules folder feels like an eternity due to its numerous dependencies. I've considered uploading just the build folder (minified version), but i ...

The CSS transition is failing to revert to its original state after being combined with animations

My goal is to create a loading animation using CSS transitions and animations. I have managed to achieve the initial loading effect by scaling with transition and then animating it to scale out on the x-axis. However, when attempting to transition back to ...

Using a combination of Ajax and jQuery in Rails4 to showcase a date in the %m/%d/%yyyy format ultimately results in a split

Recently, I encountered an issue with an ajax call that retrieves a date from the database. The date is stored as a double in the database and then converted to a string. I used Date.parse to change it into a date object and used strftime to format it. How ...

Tips for optimizing Slider Code to showcase an expanded selection of slides

I am currently troubleshooting a slider code on my ASP.NET website. After examining the HTML, JS, and CSS from the page theme, I noticed that only two slides are being displayed. However, when attempting to add a new slider HTML and adjusting the CSS for t ...

Steps to resolve background image problems

Currently encountering issues with the application where the background image is not showing up behind the login form. This problem arises while using a bootstrap template for the website. Attempted to set the background image in the .main-content div with ...

The error message being displayed states that 'null' cannot be used as an object when evaluating 'response.productType'

Hey everyone, I'm fairly new to working with Ajax and I've encountered an error in my code that says: TypeError: 'null' is not an object (evaluating 'response.productType'). I'm not sure why this is happening. Below is th ...

Tips for integrating scroll-snap and jQuery's .scroll() function together

I'm facing challenges in integrating both of these elements into the same project. When I activate overflow: scroll, my jQuery function does not work as expected. However, if I deactivate it, then the jQuery works but the scroll-snap feature does not ...

What is the process of video buffering in HTML5?

Is automatic buffering handled by HTML5? I'm planning to use video tags to display user-uploaded videos in my application. From what I've gathered, HTML5 buffers videos differently depending on the client's browser, with buffering varying ba ...

The presence of the target tag remains unchanged when a media query is used

Hello, I have a question regarding a specific issue in my code. I am trying to use a media query to make a tag disappear when the width of the window is less than 1200px, but it's not working as expected. I believe it might be related to inheritance. ...

Issue encountered when toggling flip switch in Jquery Mobile

I am trying to create a calculator for my app using Jquery Mobile, but I am facing an issue with the flip toggle switch. Here is my script: <script type="text/javascript"> function dosis() { $peso = $('#peso').get(0).value $dosis = ...

What steps do I need to take in order to transform this code into a MUI component complete with

Having some trouble converting my hero banner code to MUI in a React project. The styling is not coming out correctly. Here is the HTML code: <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120 ...

How can I use Ajax to open views in Asp.net Core 3.1?

Why is the view not being displayed even though there is no error? jQuery : $('#edit_button').on("click", function () { var instance = $('#jstree').jstree("get_selected"); if (instance != 0) ...

Adding an image to an HTML page

I am working on an HTML page and need to insert an image. Here is the code I currently have: <img src="../Images/logo.jpg" alt="Logo" height="50"> I chose "../Images/logo.jpg" as the source because my logo.jpg is located two levels up from the curr ...

Error: JQuery's on() function is not defined

After modifying the code in the original and changed code boxes, I'm now encountering an Uncaught Type error: Undefined is not a function. Any thoughts on why this might be happening? Thanks Original: $('.comment').click(function(e){ ...