disable td's from moving when hovered over

When you add a book, you will see the item added to the table with a cool font and an X icon for removal. However, I noticed that when hovering over the icon to increase its size, it slightly shifts the text in the other cells. Is there a way to prevent this from happening?

I discovered that wrapping the link in a p tag and applying width: 0 along with margin-bottom: 0 seems to fix the issue, but it feels like more of a workaround. Is there a better solution available?

function Book(title, author, isbn){
    this.title = title;
    this.author = author;
    this.isbn = isbn;
}

function UI(){}
UI.addTr = function (book){
    const table = document.getElementById("tbody");
    const row = table.insertRow(-1);

    const td0 = row.insertCell(0);
    const td1 = row.insertCell(1);
    const td2 = row.insertCell(2);
    const td3 = row.insertCell(3);

    td0.innerHTML = book.title;
    td1.innerHTML = book.author;
    td2.innerHTML = book.isbn;
    td3.innerHTML = '<a href="#" class="fa fa-remove text-align-center"></a>';

    const x = document.querySelectorAll('a');
    //console.log(x,x[x.length - 1]);
    x[x.length - 1].addEventListener('click', myDelete);
}

UI.deleteTr = function(tr){

}

function myDelete(e){
    //console.log(e.target)
}



const submit=document.getElementById('submit').addEventListener('click',mySubmit);
//console.log(document.getElementById('submit'));
function mySubmit(e){
    e.preventDefault();

    const inputs = Array.from(document.getElementsByClassName('inputs'));
    let title, author, isbn;

    inputs.forEach((input,i) => {
        switch(i){
            case 0:
                title = input.value;
                break;
            case 1:
                author = input.value;
                break;
            case 2:
                isbn = input.value;
                break;
        }
    });

    if(title == '' || author == '' || isbn == ''){
        console.log('check inputs');
    }else{
        inputs.forEach((input) => {
            input.value='';
        });
        const book = new Book(title,author,isbn);
        UI.addTr(book);
    }
}
#submit{
    height: calc(1.5em + .75rem + 2px);
    padding: .375rem .75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
}

h1{
    font-size:3rem!important;
}

#submit{
    font-size:12px;
}

body{
        letter-spacing:.1rem;
}

a, a:hover{
    text-decoration:none!important;
    color:red!important;
    text-align:left;
}

a:hover{
    font-size:larger;
}
<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title></title>

        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
        
        <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">




    </head>

    <body>
        <div class="container  w-75">
            <h1 class="display-4 mb-4">Add Book</h1>
            <form id="bookInputs">
                <div class="form-group">
                    <label class='font-weight-bold' for="title">Title</label>
                    <input type="text" class="form-control inputs" id="title">
                </div>
                <div class="form-group">
                    <label class='font-weight-bold' for="author">Author</label>
                    <input type="text" class="form-control inputs" id="author">
                </div>
                <div class="form-group">
                    <label class='font-weight-bold' for="isbn">ISBN#</label>
                    <input type="text" class="form-control inputs" id="isbn">
                </div>
                <input id='submit' type='submit' value='submit' class='font-weight-bold w-100 bg-white border border-grey rounded'>
            </form>

            <table id='myTable' class="table table-striped">
                <thead>
                    <tr>
                        <th class='border-top-0'>Title</th>
                        <th class='border-top-0'>Author</th>
                        <th class='border-top-0'>ISBN</th>
                        <th class='border-top-0'></th>
                    </tr>
                </thead>
                <tbody id='tbody'>
                </tbody>

            </table>

        </div>

        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <!--<script src="https://cdn.jsdelivr.net/npm/popper/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>-->
        <script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
        
    </body>

</html>

Answer №1

Implementing width constraints resolves the issue.

Consider this basic scenario:

#myTable td { width: 25%}

function Book(title,author,isbn){
    this.title = title
    this.author = author
    this.isbn = isbn
}

function UI(){}
UI.addTr = function (book){
    const table = document.getElementById("tbody");
    const row = table.insertRow(-1);

    const td0 = row.insertCell(0);
    const td1 = row.insertCell(1);
    const td2 = row.insertCell(2);
    const td3 = row.insertCell(3);

    td0.innerHTML = book.title;
    td1.innerHTML = book.author;
    td2.innerHTML = book.isbn;
    td3.innerHTML = '<a href="#" class="fa fa-remove text-align-center"></a>';

    const x = document.querySelectorAll('a')
    //console.log(x,x[x.length - 1])
    x[x.length - 1].addEventListener('click',myDelete)
}

UI.deleteTr = function(tr){

}

function myDelete(e){
    //console.log(e.target)
}



const submit=document.getElementById('submit').addEventListener('click',mySubmit)
//console.log(document.getElementById('submit'))
function mySubmit(e){
    e.preventDefault();

    const inputs = Array.from(document.getElementsByClassName('inputs'))
    let title, author, isbn

    inputs.forEach((input,i) => {
        switch(i){
            case 0:
                title = input.value
                break
            case 1:
                author = input.value
                break
            case 2:
                isbn = input.value
                break
        }
    });

    if(title == '' || author == '' || isbn == ''){
        console.log('check inputs')
    }else{
        inputs.forEach((input) => {
            input.value=''
        })
        const book = new Book(title,author,isbn)
        UI.addTr(book)
    }
}
/******/
#myTable td{width:25%}
******/


#submit{
    height: calc(1.5em + .75rem + 2px);
    padding: .375rem .75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
}

h1{
    font-size:3rem!important;
}

#submit{
    font-size:12px;
}

body{
        letter-spacing:.1rem;
}

a, a:hover{
    text-decoration:none!important;
    color:red!important;
    text-align:left;
}

a:hover{
    font-size:larger;
}
<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title></title>

        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8cac7c7dcdbdcdac9d8e89c869e8698">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
        
        <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">




    </head>

    <body>
        <div class="container  w-75">
            <h1 class="display-4 mb-4">Add Book</h1>
            <form id="bookInputs">
                <div class="form-group">
                    <label class='font-weight-bold' for="title">Title</label>
                    <input type="text" class="form-control inputs" id="title">
                </div>
                <div class="form-group">
                    <label class='font-weight-bold' for="author">Author</label>
                    <input type="text" class="form-control inputs" id="author">
                </div>
                <div class="form-group">
                    <label class='font-weight-bold' for="isbn">ISBN#</label>
                    <input type="text" class="form-control inputs" id="isbn">
                </div>
                <input id='submit' type='submit' value='submit' class='font-weight-bold w-100 bg-white border border-grey rounded'>
            </form>

            <table id='myTable' class="table table-striped">
                <thead>
                    <tr>
                        <th class='border-top-0'>Title</th>
                        <th class='border-top-0'>Author</th>
                        <th class='border-top-0'>ISBN</th>
                        <th class='border-top-0'></th>
                    </tr>
                </thead>
                <tbody id='tbody'>
                </tbody>

            </table>

        </div>

        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <!--<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="38485748485d4a16524b780916090e1609">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>-->
        <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89ebe6e6fdfafdfbe8f9c9bda7bfa7b9">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
        
    </body>

</html>

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

When authenticated, the value of req.user is undefined

req.user is currently undefined even though the user is authenticated. It was functioning correctly earlier but now I'm unsure about what changes I made. Currently, it renders an empty object: {} routes/user router.get('/user', (req, res ...

Adding a placeholder to a MUI Select component with different value prop and MenuItem options: a step-by-step guide

Is there a way to include a placeholder (-- Select --) in the MUI Select component below? const [country, setCountry] = useState("") <FormControl fullWidth error={!country}> <Select displayEmpty renderValue={selected => sel ...

Why does my express POST request result in an empty req.body in Node.js?

After confirming that my data is being passed correctly and the db connection is successful, I am facing an issue with my ajax request. Even though the success callback returns the id, my data seems to not be passing through properly. When attempting to a ...

Centralized Vendor Repository for Managing Multiple Angular2 Applications

Looking to host different Angular2 apps that share the same framework packages and node_modules across a main domain and subdomains: domain.com subdomain.domain.com sub2.domain.com Directory Layout public_html ├── SUBDOMAINS │ ├── sub2 ...

How can I send a variable to a service using AngularJS?

I am currently working on developing an app for movie tracking, and I am fairly new to Angular. I am facing a challenge in passing a variable to this service. Instead of hardcoding the URL, I want it to be a variable. What is the best approach to achieve ...

Comparing WebSockets and XHR for transmitting data

Looking to optimize the architecture of a web application using Node.js, the goal is to efficiently send medium-sized files to the client from a gallery. Each gallery item should be delivered to the user as quickly as possible in binary form. The file size ...

App.controller attributes in HTML tags are not receiving the value of the HTML variable

In the process of developing a simple student-teacher web application, I am utilizing AngularJS to handle the front-end. Within my JavaScript file, there are two app controllers - one for fetching student data and another for retrieving subjects assigned t ...

Achieving equal height in Bootstrap columns

Artwork Hey everyone, I'm facing a small dilemma. Currently, I am tackling a project with a unique design. Within the layout of this project, there is an image section that is causing some trouble for me. I am aiming to create a portion of the webs ...

Looking to eliminate the top border of the first cell

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="680a07071c1b1c1a4f5f5d465a465b">[email protected]</a>/dist/css/bootstrap.min.css"/> <br/> < ...

Adding Breathable Space Between Wrapper and Div Elements

Hello everyone! I am new to the world of web design and this is my first big project. Please bear with me if my code is a bit messy. I need help in reducing the space between my main content area/wrapper and footer to about 20px. Any experts familiar with ...

An easy way to activate the save button automatically

Is there a way to automatically enable the save button when a user checks the checkbox and enters text in the input field? I'm not sure what steps are needed or if there is an alternative approach to achieve this. jQuery("input[type='text&apos ...

What could be causing the delay in this script's execution?

I'm attempting to include a script at the beginning of my XBL file, however even the test below is not functioning. Any insight on why this might be happening? <bindings xmlns="http://www.mozilla.org/xbl" xmlns:xbl="http://www.mozilla.org/x ...

Is it possible to repeatedly activate a function using onmousedown just like with onkeydown?

My goal is to have the onmousedown event trigger repeatedly when the left mouse button is held down, instead of just once upon clicking. Currently, it only fires a single time. wHandle.onmousedown = function (event) { console.log('mouse b ...

Using jQuery to create a dynamically moving div that forms an endless wall

In order to create a continuous wall that pulls text from a database and displays it, I've developed the following code: $(function() { var x = 0; var y = 100.0; var z=0; setInterval(function() { x -= 0.1; y -= 0.1; ...

Meteor: The call stack has surpassed its maximum size limit

I attempted to perform an action that I have done several times before without encountering any errors. My goal is to retrieve all documents where the X field matches the value Y in my Meteor app: JS: (template helper) 'friendPictures' : funct ...

Three.js: Transparent background for background elements and png particles

I'm struggling with making the background invisible and setting the alpha channel on my particles. I was hoping to use your example script wegl_particles_sprite for the Christmas season. I adjusted it to fit my needs by placing it in a fullscreen div ...

Node.js NPM Google search results showing [ Object object ] instead of actual result

searchOnGoogle: function(searchQuery){ googleSearch.query({ q: searchQuery }, function(error, response) { console.log(response); botChat.send ...

Some devices may start the Flutter web page zoomed in by default

Experiencing Zoom Issue on Flutter Web Project: While working on my Flutter web project, I have encountered an issue where the page loads with a zoomed-in view on certain devices. Despite setting the viewport meta tag correctly, the zoom problem persists. ...

Ways to change the background image when hovering in a React component

I'm having trouble trying to scale my background image by 1.5 when the user's mouse enters. Here is the code I have so far: import React from 'react'; import Slider from './index'; import horizontalCss from './css/hori ...

Tips for creating a horizontally scrolling div

Here is the CSS for the div that needs to be able to scroll horizontally: .form-holder{ padding-left: 20px; width: auto; background: ; overflow-x: auto; max-height: 300px; padding-bottom: 30px; } Every ...