Trouble with aligning action buttons in rows or columns with CSS

I am working with an HTML table that has dynamically created rows and columns using AngularJS. I want to add an option where users can hover over a row or column and see a delete button icon that, when clicked, will remove that row or column. While this functionality mostly works as expected, there are a few issues that need addressing.

If you would like to view the code pen I have created, please visit https://codepen.io/anon/pen/PBVoOb

Here is the table code:

<table class="table table-bordered">        
      <thead>
        <tr class="actions">
          <th class="unique-id hidden-border" colspan="1"></th>
          <th ng-class="{'active': showColumnActions(c)}" ng-repeat="c in targetTable.columns track by $index"><span>
                     <a class="btn btn-xs"><i class="fa fa fa-pencil" aria-hidden="true"></i></a>
                     <a class="btn btn-xs" ng-click="removeColumn($index)"><i class="fa fa-times-circle" aria-hidden="true"></i></a></span>
          </th>
        </tr>
        <tr>

          <th class="unique-id">ID #</th>
          <th contenteditable="true" ng-repeat="c in targetTable.columns" ng-model="c.label"></th>
          <th class="view-next-set"><a href="#">...</a></th>
          <td class="center add-column"><a href="#" ng-click="addColumn()">+ Add Column</a></td>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="r in targetTable.rows" ng-mouseover="row = $index" ng-mouseleave="row = -1">

          <td class="unique-id" ng-model="r.id">{{r.id}}<div class="btn-group btn-group-xs">
              <button ng-show="row == $index" type="button" class="btn" ng-click="deleteRow($index)"><span class="glyphicon glyphicon-remove"></span></button>
            </div></td>
          <td contenteditable="true" ng-repeat="column in targetTable.columns" ng-model="r[column.id]" ng-blur="!r.id? addNewRow(r[column.id], r): undefined" ng-mouseover="setActiveColumn(column)"></td>
          <td class="blank" colspan="2"></td>
        </tr>
        <!--<tr>
                 <td class="unique-id"></td>
                 <td contenteditable="true" ng-repeat="column in targetTable.columns" ng-model="entry" ng-blur="addRow(entry, column.id)"></td>
                 <td class="blank" colspan="2"></td>
              </tr> -->
      </tbody>
    </table>

Issues:

  • Regarding Rows: When hovering over the ID column, the delete (X) icon appears. However, I would prefer to display this icon outside of the table on the left side when hovering over the ID column. How can I achieve this?

  • Regarding Columns: There seems to be an extra top border above the table that extends when adding a new column. I'm unsure what is causing this issue and how to remove the extra border. Any advice?

Answer №1

To prevent the cell from resizing and position the button where desired, consider using absolute positioning.

To remove the extra empty row, simply delete:

{}

from the following code block:

var table = {
    id: 0,
    name: "table 14",
    columns: [{ id: 0, label: "Name" }, { id: 1, label: "Age" }],
    rows: [ 

// ... your data

],
    uniqueIdCounter: 1037
};

This empty object creates an unnecessary row when there's no data to display.

For example:

td {
  position: relative; /* used as reference for absolute child */
}
div.btn-group {
  position: absolute ;/* keeps it outside the normal flow */
  left: 0; /* positions it far left within parent td */
}

Below is a demo snippet provided for illustration purposes.

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

The design of emails varies when viewed on mobile devices versus desktop computers

While creating an html email, I encountered a little issue. I have designed two layouts - one for desktop (and tablet) and one for mobile. These layouts differ in multiple ways, from images to text. To address this, I created two tables and assigned a clas ...

Turn off automatic downloading of embedded frame content in Safari for iOS

I am encountering an issue with a modal that displays a PDF and offers two options - one to print and one to download. The download option uses a blob with content-type: application/octet-stream, while the print option utilizes a blob with content-type: a ...

Issue with jQuery Quicksand's CSS rendering in Internet Explorer and Firefox browsers, but not affecting Chrome

I'm attempting to achieve an icon-swapping effect using jQuery+quicksand. Although it works seamlessly in Chrome, I am encountering issues with IE and Firefox. Given that the more intricate quicksand demos function flawlessly across all browsers, I su ...

What could be causing the malfunction of BS4 Scrollspy?

I'm having trouble with implementing Bootstrap 4's Scrollspy feature. Despite going through the BS4 documentation and watching a Scrollspy tutorial on YouTube, I still can't seem to get it to work properly. Currently, I am using a CDN for BS ...

Ways to speed up the disappearance of error messages

There is a minor issue that I find quite annoying. The validation error message takes too long (approximately 3 seconds) to disappear after a valid input has been entered. Let me give you an example. https://i.sstatic.net/8UKrm.png Do you have any tips o ...

Filtering Tables with AngularJS

Currently, I'm experimenting with using angularJS to filter data in a table. My goal is to load the data from a JSON file that has a structure like this (example file): [{name: "Moroni", age: 50}, {name: "Tiancum", age: 43}, { ...

Transforming dynamic class based on state value from React to TypeScript

I'm trying to implement this React function in TypeScript, but I'm encountering errors. const ListItem = ({ text }) => { let [showMore, setShowMore] = useState(false); return ( <div className="item"> ...

Align Bootstrap navigation bar items at the center horizontally

I am currently working on a navigation bar that features two icons, evenly distributed. To achieve this look, I have been experimenting with scaling the icons horizontally in order to make them center-aligned within the navigation bar. However, I have not ...

Creating a Triangle Slider Component with React and Material-UI (MUI)

Struggling with creating a price control using react js and MUI, similar to the image below: https://i.stack.imgur.com/ZP8oc.png I've searched online for libraries or solutions, but haven't found anything that works. ...

I am facing difficulty creating a dropdown menu with nested options that only appear when the user hovers over the main selection

Here are the parent options I have and the code I have attempted to build. I would like to include sub-options such as phones, radios, speakers under the electronics parent option and many more. <select id="category" name="category" class="dropDown"& ...

Use an external javascript file in AngularJS if permitted

To ensure that my HTML page only loads an external JavaScript file when the variable $scope.jsallowed is set to true, I attempted the following code implementation within my AngularJS based page: <script src="assets/js/slider.min.js" data-ng-if="jsallo ...

The issue with Bootstrap 4 Card Flex Width not functioning properly seems to be unique to Firefox

I'm currently facing an issue while creating a webpage using Bootstrap 4 and flex. I have Bootstrap cards with specific widths, and it seems to work perfectly fine in Google Chrome and Opera but not in Firefox. Here's the code snippet: <d ...

I'm attempting to set up three columns that fade in responsively. Is there a way to make them appear side by side instead of stacking on top of each other?

Is there a way to display the three columns horizontally instead of vertically? I also want them to adjust responsively and fade smoothly. Here is my fiddle link: https://jsfiddle.net/Spleendrivel/dswufb78/3/ <!DOCTYPE html> <html> <head ...

Setting the borderRadius for a web view on Android Maps V3: A complete guide

In my application, I am using Android Map V3 and have encountered a bug specific to the Kit-Kat version. The chromium kit throws up an error message - nativeOnDraw failed; clearing to background color, which prevents the map from being displayed. Despite ...

Customizing Bootstrap Styles in Angular: How to Override Specific Classes

Looking to customize an HTML element <div [style.color]="themeService.backgroundColor" class="col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-lg-10 col-lg-offset-1"> <ul class="pagination" id="pag-bar"> <l ...

Having trouble parsing emails in Python using the "imaplib" library, dealing with HTML line character limits, and handling extra non-Unicode characters

In my Python 3 project, I am working on validating emails that are sent to my inbox. I am using imaplib library to achieve this task. While I have successfully retrieved the email content, the mail appears to be unreadable and somewhat corrupted (reference ...

What is the best way to arrange a bootstrap .container?

I've been struggling to position a content DIV on a bootstrap carousel, but so far I haven't been successful in figuring it out. Below is a screenshot of the current output from my code, which is not what I am aiming for. What I'm trying t ...

Is the order of elements in a CSS file important?

In my situation, I am dealing with a nested list and enclosing div that was created by Drupal's menu system, so I am unable to modify it. My goal is to replicate the menu from a hardcoded website (link removed). How can I include the sub-items (ul l ...

I have a simple query about rewrite rules

Can someone help with a URL rewrite rule issue I'm having? http://www.mydomain.com/index.html I would like to rewrite the URL above to just: http://www.mydomain.com To clarify, I want to remove the "index.html" part of the URL. Does anyone know ...

HTML Tooltip with Bootstrap 4

After creating a website using Bootstrap 4 and jQuery, I encountered an issue with HTML-styled tooltips. Instead of displaying the tooltips with the correct styling, they appear to be populated using the jQuery text() function, showing the HTML as plain te ...