What is the best way to maintain the height of a table row while applying a CSS border to a cell within that row?

I am working on a jQuery script that selects a cell when clicked, and I want the row to maintain its height without changing.

Even though I have set the height of the table row using CSS, whenever I change the border of a single cell, the entire row's height adjusts...

I attempted to use the Table-Layout CSS property, but it did not solve the issue. Any suggestions on what I can do?

    .EditTable td
    {
        padding: 0px 0px 0px 0px;
        margin: 0px 0px 0px 0px;
        border-right: 1px solid #C1C1C1;
        border-bottom: 1px solid #C1C1C1;
        height: 26px;
        cursor:default;
        font-family: arial;
        font-size: 0.8em;
    }

    .EditTable td input
    {
        padding: 0px 0px 0px 0px;
        margin: 0px 0px 0px 0px;
        cursor:default;
        text-align: right;
        background-color: white;
        color: black;
        border: 0;
        outline: none;
        outline-offset: 0;
    }

<table class="EditTable" cellpadding="0" cellspacing="0">

      <tr>
            <td>
                <div style="">0</div>
            </td>
            <td>
                <div style="">0 akudsfsa fdhsad fiasgdf swae</div>
            </td>
            <td id="tempid1" class="highlightableTDCell">
                <div class="tempDiv">
                    <input id="Text2" value="0.00"/>
                </div>
            </td>
      </tr>

      <tr>
            <td>
                <div style="">0</div>
            </td>
            <td>
                <div style="">0 akudsfsa fdhsad fiasgdf swae</div>
            </td>
            <td id="Td1" class="highlightableTDCell">
                <div class="tempDiv">
                    <input id="Text1" value="0.00"/>
                </div>
            </td>
      </tr>

</table>



//highlighting cell
gridview.prototype.borderiseTDCell = function (obj) {
    //jQuery('#' + obj.id + ' div input').blur();

    jQuery(obj).find('div input').blur();
    this.unBorderiseTDCells();
    var jQueryTableCell = jQuery('#' + obj.id);
    jQueryTableCell.css('border', '2px solid #000000');

};

gridview.prototype.unBorderiseTDCells = function () {

    var cellToUnHighLight = jQuery('.highlightableTDCell');
    cellToUnHighLight.css('border-width', '0px 1px 1px 0px');
    cellToUnHighLight.css('border-color', '#C1C1C1');
};

Answer №1

This is a breakdown of the W3C box model and how it operates. By utilizing CSS to set the height of an element, you are specifically determining the height of the content inside, without taking into account any padding or borders.

Considering that a border is being added to the cell through jQuery, it becomes essential to readjust the height measurement to accommodate for the additional pixels introduced by the borders.

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

Looking for some help with tweaking this script - it's so close to working perfectly! The images are supposed to show up while

Hey everyone, I'm struggling with a script issue! I currently have a gallery of images where the opacity is set to 0 in my CSS. I want these images to become visible when scrolling down (on view). In this script, I have specified that they should app ...

What could be causing my application to not locate the jquery module? ERROR: ENOENT: The specified file or directory cannot be found

I've decided to bring over an Angular project that already has a bootstrap template integrated into my own project. (Still unsure if this was the right move) One of the steps I took was adding these lines to the angular.json file: "styles": [ ...

Choosing the Angular5 model

I'm currently working with an Angular5 project that has a <select> element bound to an array of customers. Here's the code snippet: <select class="form-control" [ngModel]="record.customer_id" (ngModelChange)="setCustomer($event)" name=" ...

Include a basic downward-pointing arrow graphic to enhance the drop-down navigation menus

I am working on a website that has drop-down menu headings styled with CSS. I am looking to enhance these certain menu headers by adding small down-facing arrows indicating they are clickable. Does anyone have any suggestions on how I can achieve this? ...

"Trouble with script: external JavaScript file failing to run

The issue lies in the fact that the specified external JavaScript file is not being executed: <script src="//www.google-analytics.com/cx/api.js?experiment=YOUR_EXPERIMENT_ID"></script> Even when I try to directly access the URL, it downloads ...

Creative ways to position and underline text using CSS

I'm having difficulty with positioning the text and extending the underline to the edge of the screen in order to create a specific visual effect. .header { height: 550px; width: 100%; background-color: #1F2041; position: relative; } . ...

Why is it not possible to incorporate a variable in HTML when using Vue.js?

Why am I encountering an error when trying to use location information in HTML? The error message is Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'geoLocationPlace'). What could be causing the variable 'geoLoc ...

Node JS server fails to load CSS even with the use of express.static

It's quite absurd, but I've been grappling with a rather nonsensical code conundrum for days now. I just can't seem to get the CSS and image to load on my Node.js server. I've tried various solutions (like express.static, etc.), but n ...

Show user information from a MySQL database in a dynamically generated table using PHP

I am working on developing an absence tracking system using PHP and MySQL. Each absence is categorized by a specific leave type, such as sick or emergency. The goal is to present this information in an HTML table format where the names of users are display ...

picture located in the top corner of the page within the diva triangle shape

Is there a way to position my photo on the same level as a div and have it overlap slightly? <div id='triangle-topleft'> <img id="photo" src="photo.png"> </div> #triangle-topleft { width: 0; heigh ...

Updates to Firebase data do not automatically reflect in Google Charts

I've successfully connected my Firebase to Google Charts, however I am facing an issue in displaying a 'no data' message when there is no data available. Currently, I have set a Firebase data value of 'NA' for a single user, which ...

Issues with jQuery autocomplete when using special characters (Norwegian)

On my website in Norway, I am facing an issue with jQuery's autocomplete function. When users type in the Norwegian characters æ, ø, and å, the autocomplete feature suggests words with these characters within them but not ones that start with these ...

Building a custom tooltip for a Bootstrap multiselect dropdown menu

I have been attempting to implement a tooltip on a multiselect dropdown menu that I constructed using the Bootstrap-select jQuery plugin... Here is how I coded my select in the HTML... <select id="dropDownList" class="selectpicker" t ...

I am having trouble viewing elements located below a div that I created using CSS

Currently, I am working on creating a portfolio page where the initial page opens with a height of '100vh' and width of '100%', which seems to be functioning correctly. However, I am facing an issue where I am unable to scroll down to v ...

Prevent reloading the page when adding a flash element using JavaScript (jQuery)

Here is the function I am working with: function onVideo(vchat, idUser){ $('#videollamada').html('<div class="videollamada">'+ '<div align="right">'+ ...

The Popover style from React-Bootstrap seems to be missing when applied to my component

Attempting to incorporate a Popover with overlay trigger from React - Bootstrap has proven to be quite the challenge. If you check this image, you'll see what it's supposed to look like. This is the code I used: var {Button, Overlay, OverlayTr ...

Implement jquery styling to ajax response

Incorporating a jquery carousel to showcase images within a dynamically updated list has proven fruitful initially. However, once the content within the carousel container is replaced via ajax, all formatting seems to vanish. The root cause of this issue ...

When I try to open my modal in Electron by clicking on the button, it doesn't work

I was expecting the modal to open by clicking on the Edit button within #app, but it doesn't open at all! I am unsure if there is an issue with my JavaScript logic or my HTML code! When attempting to use a function for the Modal, it still does not wo ...

Looking to have images and text aligned horizontally within a grid layout?

<div> <button style=" padding: 10px 16px 10px 16px; vertical-align: middle; margin: auto; width: 32%;"> <img style=" width: 22px; height: 22px; vertical-align: middle; " src="https://upload.wikimedia.org/wiki ...

Flask does not provide a direct boolean value for checkboxes

After struggling for a week, I am still lost on where to make changes in my code. I need the checkbox to return a boolean value in my Flask application. Below are snippets of the relevant code: mycode.py import os, sqlite3 from flask import Flask, flash ...