Tips for making an input field that overlays text

I am currently working on a project that involves creating multiple cards using Bootstrap. Each card consists of a header, body, and footer. When a card is clicked on, I want an input field to appear in the header, footer, and body sections, overlaying the current text content. Although I have successfully toggled the class, I am facing challenges in aligning the input fields over the text.

Below is the HTML structure:

`<div class='card-deck col-3' id='deck'>
        <div class='card grow'>
            <div class='card-header par'>
                <h3 class='target'>${tasks.task}</h3>
                <input id='updateTask' placeholder='Task'>
            </div>
            <div class='card-body par'>    
                <h6 class='target'>Due by: ${newDate}</h6>
                <input id='updateDate' placeholder='Date'>
            </div>
            <div class='card-footer par'>    
                <h6 class='target'> Priority: ${tasks.priority}</h6>
                <input class='update' id='updatePriority' placeholder='Priority'>
            </div>
        </div>    
    </div>`

Here is the JavaScript code used to toggle classes:

let card = $(this)
card.children('.par').children('.update').toggleClass('hidden');
card.children('.target').toggleClass('remove');

Lastly, here is my current CSS styling:

.par{
     position: relative;
}

#updateTask, #updateDate, #updatePriority{
    position: relative;   
    z-index: 999;
}

.hidden{
     display: none; 
    z-index: -999;
}

In setting the 'par' class for each input and text set to relative positioning, I then positioned the input fields as absolute. Despite trying different combinations of positioning and restructuring divs, I have not been able to stack the input fields over their respective text successfully.

Unfortunately, the JSfiddle does not work due to my usage of bootstrap in this project.

Answer №1

We will be implementing the function to apply the "toggleClass" call to each element.

$('#deck input').each(function(index, element){
 $(element).toggleClass('hidden');
});

Simply select all .target elements within #deck and delete them.

$('#deck .target').remove();

Regarding the .hidden class, using display:none is recommended but keep in mind that the z-index property requires a position property to work properly. (It only functions on positioned elements such as position:absolute, position:relative, or position:fixed) https://www.w3schools.com/cssref/pr_pos_z-index.asp )

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

translating xpath code into css styling

Can you help me with converting this xpath to css? By.xpath("//div[@id='j_id0:form:j_id687:j_id693:j_id694:j_id700']/div[2]/table/tbody/tr/td"); I've tried a couple of options, but none of them seem to work: By.cssSelector("div[@id=&apos ...

What is the best way to emphasize a specific data point within a chart created with chartjs, especially when the data is sourced from a JSON

// Here I am retrieving another set of data in JSON format from a PHP file $(document).ready(function () { showGraph(); }); function showGraph() { $.post("phpfile.php", function (data) { console.log(data); var name = []; v ...

The MaterialTable is unable to display any data

After calling the fetch function in the useEffect, my getUsers function does not populate the data variable. I am unable to see rows of data in the MaterialTable as the data structure is in columns. I need help figuring out what I'm doing wrong. func ...

JavaScript: creating and saving unique random selections without repetition

Currently, I am grappling with using Javascript to generate an array, select two distinct random elements from the array, and then allocate these selected values to an HTML table. My strategy has involved initializing an array, picking a random value, gene ...

Displaying MySQL results in a vertical sequence

I've stored the data in my database as follows: Football ART-NR-1337 Price: 5$ Basketball ART-NR-1333 Price: 10$ Now, I am working on a .php file that displays the articles like this: Football Basketball ART-NR-1337 ART-NR-1333 Price: 5$ ...

Issue [ERR_REQUIRE_ESM]: Importing an ES Module using require() is not compatible with node_moduleswrap-ansiindex.js

Encountering an issue in my nestjs project with a library that is indirectly used by a third-party. stringWidth = require('string-width') in node_modules\wrap-ansi\index.js:2 not supported Here are the dependencies listed in package. ...

Using JavaScript to search JSON objects based on key value pairs

Consider a scenario where you have an array of objects in users.json: {"key":"userSubscriptions","value": [{"channel":"Netflix","user":"Bobby","region":"NA"}, [{" ...

Having trouble retrieving data from a remote URL with angucomplete-alt

Utilizing the angucomplete-alt directive for creating an autocomplete list through a get request. Successfully fetching results from the Github API: <div angucomplete-alt id="ex5" placeholder="Search projects" pause="500" selected-object="selectedProj ...

Is there a similar effect in jQuery? This is achieved using prototype

Simply click on the comments link. Observe how the comments smoothly appear, as if sliding down. Also, try clicking on 'hide' and see what happens. ...

Tips on showcasing a JSON object containing two arrays in HTML using a pair of for loops

I am facing an issue with displaying data from two tables in my PHP script. The personal information is being displayed correctly, but the books related to each person are not showing up. I suspect that my approach might not be efficient enough for handlin ...

When attempting to submit, the jQuery validations fail to function accordingly

I have created an HTML form along with jQuery for validation purposes. However, upon clicking the submit button, nothing seems to be happening. I am unsure if my form is properly connecting with the jQuery file or not. Can someone please review my code and ...

The contrastText property of the MUI React Theme palette is not functioning properly

I am working with MUI React to design a menu and I have utilized the AppBar component. I would like to customize it in the following way: brown.myBrown = '#544846'; const brownTheme = createTheme({ palette: { primary: { ma ...

Tips for aligning a website logo and header vertically with the navbar

I'm having trouble aligning the navbar vertically with my website logo and header. I've tried using display: inline-block; and vertical-align: middle; on the , , and tags within the same div at the top of my website, but it ends up switching fro ...

Efficiently adjust the width of a child div to automatically fit within

I stumbled upon this fascinating jsfiddle on this website that almost completely addresses my concern, solving up to 90% of it. Check out the JSFiddle Nevertheless, I am keen to incorporate margins within the inner divs. Despite attempting to modify the ...

CSS: Continuous Automated Slide Transitions

What CSS code do I need to incorporate into my code to create a continuous Slider Animation? I want the pictures to slide automatically one by one, with a specified time interval between each slide when not on hover. The hover function is already included ...

Laravel 8 - sweet alert functions properly, however, the ajax functionality is not functioning as expected

As a newcomer to Ajax, I am facing an issue with deleting records from the database using Sweet Alert2. Although my swal is working fine, the ajax function seems to be malfunctioning. Can anyone point out where the problem might be and suggest a solution? ...

How can I use Angular to dynamically open a video that corresponds to a clicked image?

I need assistance with a functionality where clicking on an image opens a corresponding video on the next page. The issue is that all images have the same ID, making it difficult to link each image to its respective video. Below is the data I am working ...

I'm looking for ways to utilize the pageLoad function across multiple user controls

I am facing an issue with 3 usercontrols on a page. Each usercontrol has a pageLoad function in JavaScript, and the page itself also has a pageLoad function. However, only the pageLoad function of the last usercontrol that I registered is being fired, whil ...

The function of the 'Class' attribute is not functioning properly

I am currently working on a search field with a drop-down menu that determines the type of data being searched. This, in turn, dictates the input type for the search field. For example, if I am searching by "name" or "ID number", the input type is set to t ...

Error: Typically encountered when trying to bind a live event to an undefined object

While developing an application in PHP with AJAX functionality, I encountered a problem specific to Internet Explorer (tested on version 8.0.6001.18702). However, the application works perfectly fine on browsers like Firefox, Chrome, and Opera. The specif ...