How to use CSS to add a pseudo element to a table and position it outside of the parent's boundaries on the left

I am currently utilizing the "ag-grid" data-table library (along with Angular 2, although the framework is not crucial) which highlights a selected row (using the default class .ag-row) by adding the class .ag-row-selected to it. Each row contains numerous cells with the .ag-cell class.

My goal is to achieve row selection not by changing the background color, but by indicating the selected row on the left and right sides with a "stripe". One way to achieve this is by adding an empty column at the beginning and end of the table and then implementing the following:

$selection-padding-width: 6px;
ag-grid-angular {
  height: 100%;
  // creating space for selection-padding-stripe:
  width: calc(100% - 2 * #{$selection-padding-width});
}
/deep/ .ag-row-selected:before {
  height: 25px;
  width: $selection-padding-width;
  content: ' ';
  display: inline-block;
  background-color: $cyan;
  transform: translateX(-1px);
}

You can view the outcome here: https://i.sstatic.net/saBKN.png

However, when I attempt to shift the blue stripe from the leftmost cell's position to the empty left area, it disappears because that empty area extends beyond the container's bounds (refer to

width: calc(100% - 2 * #{$selection-padding-width});
). I am curious to know if there is a way to make the selection-padding (blue stripe) visible above the container, for instance, by appearing when transform: translateX(-6px) is applied to it.

If you wish to observe ag-grid in action, you can check out this plunkr: https://plnkr.co/edit/ehKrzYNuZ64CYBOClbL6?p=preview

Answer №1

To effectively address this issue, as recommended by ovokuro's comment, the optimal approach is to utilize a border. It is advisable to apply this border to the row instead of the cell. This ensures that when you move the cell, the border remains fixed on the left or right of the entire row, rather than moving along with the cell. Ultimately, the solution can be implemented as follows:

/deep/ .ag-header-row {
  background-color: $table-header-color;
  border-left: $selection-padding-width solid $table-header-color;
  border-right: $selection-padding-width solid $table-header-color;
}

/deep/ .ag-row-even:not(.ag-row-selected) {
  border-left: $selection-padding-width solid $even-row-color;
  border-right: $selection-padding-width solid $even-row-color;
}

/deep/ .ag-row-odd:not(.ag-row-selected) {
  border-left: $selection-padding-width solid $odd-row-color;
  border-right: $selection-padding-width solid $odd-row-color;
}

/deep/ .ag-row-selected {
  border-left: $selection-padding-width solid $cyan;
  border-right: $selection-padding-width solid $cyan;
}

/deep/ .ag-row-even, .ag-row-even.ag-row-selected {
  background-color: $even-row-color!important;
}

/deep/ .ag-row-odd, .ag-row-odd.ag-row-selected {
  background-color: $odd-row-color!important;
}

/deep/ .ag-header-container {
  left: 0!important;
}

/deep/ .ag-body-viewport {
  overflow-x: hidden!important;
}

The final sections at the end are crucial to prevent overflowing of the header and body. This occurs because ag-grid automatically adds spacing when a column is moved to the rightmost position, and there is a border attribute on the rows. The !important declaration is necessary due to the addition of certain classes by ag-grid programmatically, which also define the same attributes.

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

Fluidity of Containers on Mobile Devices

I currently have a list structured like this: https://i.sstatic.net/ei4Xt.png In order to display more details about each list item, I've added a hidden div that can be toggled open like so: https://i.sstatic.net/61k5Z.png While this works fine on ...

Retrieving a compilation of items found within text selected by the user on a website

Imagine a scenario in which a webpage contains the following structure: <p> <span class="1">Here's some text</span> <span class="2">that the user</span> <span class="3">could select.</span> </p> I ...

Ensure that the JSON file containing translations is fully loaded prior to proceeding with the loading of the Angular application

In our Angular application, we have integrated internationalization using ng2-translate. We are utilizing the .instant(...) method for translations to simplify the process without having to subscribe to observables. One issue we are facing is that using . ...

Is there a way to extract the properties of a CSS class from a stylesheet and convert them into a hash using JavaScript or jQuery?

I am exploring a way to extract key value pairs from a CSS stylesheet related to a specific class or id into a JavaScript object for data accessibility. It is important to mention that I do not intend to apply this class directly to any DOM elements. In ...

What is the best way to share CSS styles between React and React Native?

Is it recommended to use inline CSS styles in a React / Next.js app to maintain code consistency across projects? For example, like this: import {StyleSheet, Dimensions} from 'react-native'; const vw = Dimensions.get('window').width / ...

Concerns with combining key value pairs in Typescript Enums

Could you help me figure out how to properly implement an enum in my drop-down so that I can only display one value at a time? Currently, I am seeing both the key and the value in the list. This is my enum: export enum VMRole { "Kubemaster" = 0, "Kub ...

Issue encountered when attempting to access interface field in HTML template of Angular 2

export interface Candidate { name: string; surname: string; gender: boolean; dateOfBirth: Date; placeOfBirth: string; originRegion: string; originDivision: string; originSubDivision: string; employmentSituation: string; typeHandicap: st ...

Issue with Color Attribute in Heading within an Ionic Content Element

The color attribute doesn't seem to be working in Ionic 2. It works fine with normal Ionic tags, but not with HTML tags. Can someone help me with this? The code is provided below. <ion-content> <div class="page-home"> <h1 color="second ...

Utilizing CSS grid layouts to ensure images expand to fit the dimensions of the designated column and

I am currently working with a CSS grid layout that is displaying as follows: .image__gallery-grid { max-height: none; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 2.5rem; dis ...

Load information into a different entity

I need help with adding new values to an existing object. When I receive some form data from noteValue, I also have additional input data in my component under person that I would like to integrate into noteValue before saving it. let noteValue = form.va ...

How can I align the kendoMenu in the center when the menu width is unpredictable?

Presenting a modified menu structure: <html class="k-webkit k-webkit40"> <head> <title>Site Title</title> <!-- js and css files referenced here --> </head> <body> <link h ...

What could be causing the issue with the padding-top not being applied to my section?

I'm having trouble getting the desired 150px padding to appear on the top and bottom of a section in my project. Here's an example: Below is the code for the section: .wp-block-mkl-section-block .section-bg { position: absolute; top: ...

Angular service encounters NotYetImplemented error due to DOCUMENT injection token in SSR

I have a unique Angular SSR app with a special service that utilizes the document. I cleverly utilize the DOCUMENT injection token to provide this essential document for dependency injection. To take a peek at my innovative approach, check out my repo here ...

Attempting to align an image in the middle of a webpage using CSS styling

Solving simple CSS problems used to be a breeze for me with just some trial and error. However, I've been struggling all day without any success. At this point, I'm at a loss for what to do. My current challenge is centered around aligning an im ...

Benefits of Angular Signals - Why is it advantageous?

I'm grappling with the concept of Angular Signals and their benefits. While many examples demonstrate counting, I'm curious about why signals are preferable to using variables like myCount and myCountDouble as shown below? Check out my code on S ...

Tips on narrowing the left margin of a div when the size of the contained element becomes too large

I am facing a challenge in formatting text on the web that contains equations embedded as SVG images. To address this issue, I have replaced the SVG elements with fixed-sized div in the example provided below. The SVG element is nested within a div specifi ...

Implementing dynamic CSS switching for right-to-left (RTL) support in a multilingual Next.js application

As I work on my multilanguage application with Next.js, I'm encountering a challenge in dynamically importing the RTL CSS file for Arabic language support. My aim is to seamlessly switch between RTL and LTR layouts based on the selected language. M ...

Angular text input with customizable placeholder text and embedded icon

Hey there, I'm looking to create a unique custom textbox that includes a text placeholder and a help icon that will display useful information in a popover. https://i.sstatic.net/Zh0IK.png When typing into the input, the textbox should have a specif ...

Escaping from its container, text breaks free with the power of CSS

Experiencing difficulties with CSS flex layout that are proving challenging to resolve. HTML: <div class="image-view"> <div class="info"> <span class="label title">d37ci4x.jpg</span> <span class="label scale ...

Maintaining Scene Integrity in THREE.JS: Tips for Handling Window Resizing

My layout includes a div with a scene that looks great initially; however, as soon as I start moving or resizing the window, the scene overflows the boundaries of the div and goes haywire, almost filling the entire window. Are there any techniques or solu ...