What are some common reasons why CSS and Bootstrap code can unexpectedly break?

I have been working on two tabs (tab-one, tab-two) where one is visible and the other is hidden. However, there has been an issue where the code breaks between the bottom of tab-one and the top of tab-two, causing some portion of tab-two to be occasionally visible.

Here is the functional code that typically works correctly

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>

    <div class="tab-one">
        <div class="form-group reg-form-group-mar">
            <div class="row">
                <div class="col-md-6 reg-form-col-6">
                    <div class="reg-lab-hi">
                        <label for="firstname">First Name</label>
                    </div>
                    <input type="firstname" class="form-control input-title firstname" id="firstname" name="firstname">
                    <div class="reg-err"></div>
                </div>
                <div class="col-md-6 ">
                    <div class="reg-lab-hi"><label for="lastname">Last Name</label></div>
                    <input type="lastname" class="form-control input-title lastname" id="email" name="email" >
                    <div class="reg-err"></div>
                </div>
            </div>
        </div>
    </div>    
    <div class="tab-two display-none">
        <div class="form-group reg-form-group-mar">
            <div class="row">
                <div class="col-md-6 reg-form-col-6">
                    <div class="reg-lab-hi">
                        <label for="email">Email</label>
                    </div>
                    <input type="email" class="form-control input-title email" id="email" name="email">
                    <div class="reg-err"></div>
                </div>
                <div class="col-md-6 ">
                    <div class="reg-lab-hi"><label for="password">Password</label></div>
                    <input type="password" class="form-control input-title password" id="password" name="password">
                    <div class="reg-err"></div>
                </div>
            </div>
        </div>
    </div>

Sometimes the code breaks in this manner

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>

    <div class="tab-one">
        <div class="form-group reg-form-group-mar">
            <div class="row">
                <div class="col-md-6 reg-form-col-6">
                    <div class="reg-lab-hi">
                        <label for="firstname">First Name</label>
                    </div>
                    <input type="firstname" class="form-control input-title firstname" id="firstname" name="firstname">
                    <div class="reg-err"></div>
                </div>
                <div class="col-md-6 ">
                    <div class="reg-lab-hi"><label for="lastname">Last Name</label></div>
                    <input type="lastname" class="form-control input-title lastname" id="lastname" name="lastname">
                        
                        <!-- {{ code breaks here }} -->
                        <label for="email">Email</label>
                    </div>
                    <input type="email" class="form-control input-title first-name" id="email" name="email">
                    <div class="reg-err"></div>
                </div>
                <div class="col-md-6 ">
                    <div class="reg-lab-hi"><label for="email">Password</label></div>
                    <input type="password" class="form-control input-title password" id="password" name="password">
                    <div class="reg-err"></div>
                </div>
            </div>
        </div>
    </div> 

I am currently using custom jQuery to handle the tab visibility. I have tried adjusting the order of the Bootstrap link and my own CSS, as well as placing JavaScript at different locations within the HTML document, but the issue persists. If you have any suggestions or solutions, please let me know!

Any advice on how to resolve this problem would be greatly appreciated.

Answer №1

After reviewing your code, I have identified an issue with the order of the div and input type elements. To resolve this problem, please update the provided HTML code with the corrected version below:

<div class="tab-one">
    <div class="form-group reg-form-group-mar">
        <div class="row">
            <div class="col-md-6 reg-form-col-6">
                <div class="reg-lab-hi">
                    <label for="firstname">First Name</label>
                </div>
                <input type="text" class="form-control input-title firstname" id="firstname" name="firstname">
                <div class="reg-err"></div>
            </div>
            <div class="col-md-6 ">
                <div class="reg-lab-hi"><label for="lastname">Last Name</label></div>
                <input type="text" class="form-control input-title lastname" id="lastname" name="lastname">

            </div>

            <div class="reg-err"></div>
        </div>
        <div class="row">
            <div class="col-md-6">

                <div class="reg-lab-hi"><label for="email">Email</label></div>

                <input type="email" class="form-control input-title email" id="email" name="email">

                <div class="reg-err"></div>
            </div>
            <div class="col-md-6 ">
                <div class="reg-lab-hi"><label for="password">Password</label></div>
                <input type="password" class="form-control input-title password" id="password" name="password">
                <div class="reg-err"></div>
            </div>
        </div>

    </div>
</div>
</div>

Please note: When using Bootstrap themes, ensure that each container is correctly assigned.

Answer №2

If you are looking for the tab option, check out the example below:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>

    <ul class="nav nav-tabs" id="myTab" role="tablist">
      <li class="nav-item">
        <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
      </li>
    </ul>
    <div class="tab-content" id="myTabContent">
      <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
      <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
      <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
    </div>

Ensure that you have included the jquery.min.js, bootstrap.min.css, and bootstrap.min.js files.

This approach eliminates the need for writing additional logic to show and hide tabs.

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

Performing real-time arithmetic calculations on dynamic text input fields using AngularJS

In the process of creating a dynamic form, the number of textboxes is determined by the situation at hand. Each textbox is assigned an arithmetic formula, which is obtained from a database table. The structure of my form will be as follows: <div ng-ap ...

What's the best way to show floating point numbers in a concise format while also maintaining the ability to perform calculations within this Vue app?

I'm currently developing a compact calculator application using Vue 3 and implementing some custom CSS. For the most part, everything seems to be functioning correctly, except for when the results are long numbers that extend beyond the display limit ...

Customizing the tab content background color in MaterializeCSS

I've been struggling to customize the background color of my MaterializeCSS tabs content by referring to their official documentation: If you visit the website, you'll notice that the default tabs have a white background, while the 'Test 1& ...

Unable to resize query as anticipated

I have been attempting to adjust the height of an HTML element only when the window is resized; however, the script seems to execute even when the window size remains the same. Despite exploring various online resources and experimenting with different scr ...

Comparing two datetime objects with time zone offsets in JavaScript: How to determine if one is greater than or less than the other?

So I'm faced with a situation where I need to compare two dates where the first date is 05.01.2008 6:00 +5:00 and the second date is 05.01.2008 7:00 +5:00 I'm struggling to find a way to convert these datetimeoffsets into a specific forma ...

Please upload a file using Ajax and jQuery in a WordPress plugin by selecting the file

Currently, I am working on a WordPress admin plugin that includes a mail feature. I would like to include the functionality to attach a file dynamically and send it through email as an attachment. I have been using the Ajax method for this, but I am unsure ...

An error stating that "DataTable is not a recognized function" occurred within the document function

Previously, I set up datatables using the code below: $(function () { $('#keywords-table').DataTable({ "ajax": ({ url: "{{ route('getKeywordsByProductId') }}", method: "get", ...

Trouble displaying images from JSON file in AngularJS using ng-src - need help with image loading

While utilizing AngularJS to extract image data from a JSON file, everything seems to work fine for other types of data except images. Why is the ng-src not retrieving any images? I am attempting to load all the images into the div and set the src, alt, a ...

Create collapsible horizontal submenus in Bootstrap for mobile devices

I created a modal specifically for mobile users that displays when they access the site. It features various categories and nested menus for easy navigation. <!-- Modal --> <div class="modal fade" id="exampleModalCenter" t ...

The text that follows the cursor seems to stand out taller than the rest

When I type words in a textarea input field, the cursor seems to be taller than it should be (as shown below). What is causing this issue and is there a way to make it as tall as the words with a font size of 38px? Here is the code snippet: <textarea n ...

Can you please adjust the image to the right side?

I'm having trouble aligning the image to the left in my code. It always seems to leave a margin on the sides that I can't figure out how to get rid of. https://i.sstatic.net/kKwII.jpg This is the snippet of my code: <section class="conta ...

I am encountering an issue with the Link tag from next/link that is throwing an error. The error message states: "React.Children.only expected to receive a single React element

Hey everyone, I've come across an issue with using next/link in my code. Every time I replace the anchor tag with the "Link" tag, I encounter an error. I've searched for a solution but haven't found one yet. Any help would be greatly appreci ...

HTML5 for advanced positioning and layering of multiple canvases

I have 2 canvas layers stacked atop each other, but I need to position them relative to the entire page. The dimensions of both layers are fixed at a width of 800 and a height of 300. My goal is to center the canvas layers regardless of screen size, with ...

Updating a data table using POST values in ASP.NET: A step-by-step guide

I am working on updating values in my database and want to ensure that my script is functioning correctly. In order to check, I created a POST method to send the values and confirm they are being received. https://i.sstatic.net/h0IH5.gif Now, my question ...

Issues arise when attempting to utilize a jQuery function to call an asp.net web method

In my ASP.NET project, I have a web method that looks like this: [WebMethod] public string getCurrentDate() { return DateTime.Now.ToString(); } My jQuery ajax call to this web method is as follows: $.ajax({ type: "POST", url: "jqueryAjax/Defau ...

Load various PHP objects using asynchronous JavaScript (AJAX) requests

In my work with CodeIgniter, I have a controller that sends me various vacancies to display in a view. The dynamic code in the view is structured like this: <div class="row vacancy-grid"> <?php foreach ($vacancies as $vacancy) { ?> ...

What is the process for adjusting the color of a mat-divider?

Has anyone been successful in changing the color of mat-divider? I attempted the following but had no luck: component.html <mat-divider class="material-devider"></mat-divider> component.scss .material-devider { color: red } ...

Display the entire paragraph when hovering over it

Is there a way to make the entire paragraph appear on hover instead of just showing parts of it? I am building a website on Weebly for a school project and my knowledge is limited. I tried using the following code, but it only displays some of the content ...

Need help fixing my issue with the try-catch functionality in my calculator program

Can someone assist me with my Vue.js calculator issue? I am facing a problem where the output gets added to the expression after using try and catch. How can I ensure that both ERR and the output are displayed in the {{output}} section? Any help would be a ...

Using the Twit package on the client side: a step-by-step guide

I have been utilizing the Twit package for searching tweets. After executing the js file in the console, I am able to see the tweets but when trying to use them on my webpage, an error 'Uncaught ReferenceError: require is not defined' pops up. Th ...