Utilize CSS on a div element enclosed within a td element

I have been attempting to align the triangle over the edge of the table cell on both ends. However, part of the triangle is being hidden. I have tried using z-index, but it doesn't seem to have any effect. Can anyone provide insight into what might be going wrong here?

https://i.sstatic.net/8eIYe.png

Expected:

https://i.sstatic.net/HXkUh.png

Shown below is my Angular code:

<td *ngFor="let col of getNumberRange(1, maxDuration)" style="padding: 0;">
  <div style="position: relative;">
    <div *ngIf="col == 1" class="triangle-up"></div>
    <div *ngIf="col == 1" class="start-abbreviation">START</div>
    <div *ngIf="col == 5" class="end-abbreviation">END</div>
    <div *ngIf="col == 5" class="triangle-down"></div>
    <div *ngIf="col >= 1 && col <= 5" 
      style=" height: 15px; background-color: #1f4166; padding-top: 5px"></div>
    </div>
</td>
.triangle-up {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 10px solid #ff6600;
  position: absolute;
  top: 0;
  left: -5px;
  z-index: 1;
}

.start-abbreviation {
  display: inline-block;
  margin-left: 5px;
  position: absolute;
  top: 0px;
  color: white;
  left: 0;
  z-index: 99999999999;
}

.triangle-down {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 10px solid #ff6600;
  position: relative;
  top: -13px;
}

.end-abbreviation {
  display: inline-block;
  margin-right: 5px;
  position: absolute;
  top: 0px;
  color: white;
  left: 0;
  z-index: 99999999999;
}

Answer №1

One possible reason for this issue could be the absence of the overflow: visible property in the container. Adding this CSS property to the parent elements can make the arrow visible. Additionally, some extra CSS styling has been implemented to mimic the appearance shown in the screenshot.

css

/* Add your application styles and imports here! */
.triangle-up {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 10px solid #ff6600;
  position: absolute;
  top: -7px;
  left: -4.5px;
  z-index: 1;
}

.start-abbreviation {
  display: inline-block;
  margin-left: 5px;
  position: absolute;
  top: -11px;
  color: white;
  left: 0;
  z-index: 99999999999;
}

.triangle-down {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 10px solid #ff6600;
  position: absolute;
  top: -7px;
  right: -4.5px;
}

.end-abbreviation {
  display: inline-block;
  margin-right: 5px;
  position: absolute;
  top: -11px;
  color: white;
  left: 0;
  z-index: 99999999999;
}

.cell-wrapper {
  padding: 0;
  height: 15px;
  background-color: #1f4166;
  padding-top: 5px;
  min-width: 50px;
  overflow: visible !important;
}

Check out the Stackblitz Demo

Answer №2

Ensure the .triangle-up and .triangle-down elements align properly with the table cell edges by adjusting their top and bottom values accordingly.

.triangle-up {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 10px solid #ff6600;
    position: absolute;
    top: -10px; /*adjust as needed*/
    left: 0;
    z-index: 1;
}

.start-abbreviation {
    display: inline-block;
    margin-left: 5px;
    color: white;
    z-index: 99999999999;
}

.triangle-down {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 10px solid #ff6600;
    position: absolute;
    bottom: -10px; /*adjust as needed*/
    left: 0;
    z-index: 1;
}

.end-abbreviation {
    display: inline-block;
    margin-right: 5px;
    color: white;
    z-index: 99999999999;
}
<td *ngFor="let col of getNumberRange(1, maxDuration)" style="padding: 0; position: relative;">
    <div *ngIf="col == 1" class="triangle-up"></div>
    <div *ngIf="col == 1" class="start-abbreviation">START</div>
    <div *ngIf="col == 5" class="end-abbreviation">END</div>
    <div *ngIf="col == 5" class="triangle-down"></div>
    <div *ngIf="col >= 1 && col <= 5" style="height: 15px; background-color: #1f4166; padding-top: 5px;"></div>
</td>

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

On mobile devices, table rows do not stretch across the full 100% width

I'm facing an issue with a table I'm using for a shopping basket on my website. Everything seems to be working fine until I added a tfoot element, causing the tbody to not span 100% of the container's width. I've been troubleshooting a ...

Starting object arrays in Angular 6 using ES6

As someone who is just starting out with javascript, I have encountered a challenge with a nested class structure. Specifically, I am looking to initialize an array of EventDate objects and assign it to 'this.dates' within the CustomerEvents cons ...

Tips for duplicating specific div elements

Is there a way to create copies of selected divs within the same panel using a Javascript report designer? I attempted to achieve this by using the following code snippet: function DesignerClone() { $(".ui-selected").each(function () { va ...

What steps should I take to ensure my clock stays in sync with my runTime function?

I am developing a mini digital clock project with the ability to mimic a physical clock. The clock is activated by using a power button to switch it on and display the current time. It should also be able to turn off and show an empty screen. However, th ...

How can I simulate event data while testing a function that is triggered when an event is emitted from another component in Angular integration testing?

Within component A, there is a function responsible for updating the view based on data emitted from component B. The aim is to simply call this function and pass the data without integrating with component B as it would be too complicated for this particu ...

Would you like to justify to the right?

I am attempting to align the final element in a list to the right side: <ul> <li>one</li> <li>two</li> <li>three</li> <li id="right">right?</li> </ul> li { display: inline-bl ...

Encountering an Error: ExpressionChangedAfterItHasBeenCheckedError, whilst conditionally modifying an attribute of

One interesting approach I'm using is to conditionally add title attributes to elements. Here's an example: <div #optionEl class="option-title" [attr.title]="isTitleTruncated(optionEl) ? option.title : null"> {{option.title}} </div& ...

Ensure that the standard icon is properly aligned with the stacked icon of equal size

Seeking guidance on aligning two icons to be the same size. Here is what I'm aiming for: https://i.sstatic.net/SHuH9.png However, in current development, they appear like this: https://i.sstatic.net/crfdl.png When attempting to resize the stack ic ...

What may be causing the MuiThemeProvider to override the style of a component?

Within my outer component, I am utilizing MuiThemeProvider: <MuiThemeProvider theme={full_theme_e}> <div> <AppBar /> <Filter /> </div> </MuiThemeProvider> Inside the Filter component, I have specified a ...

Testing Angular components using mock HTML Document functionality is an important step in

Looking for help on testing a method in my component.ts. Here's the method: print(i) { (document.getElementById("iframe0) as any).contentWindow.print(); } I'm unsure how to mock an HTML document with an iframe in order to test this meth ...

Using HTML's select option to submit a request for data retrieval from PHP using PDO with MySql database

I am having an issue with fetching data from MySQL based on Select Month and Year in HTML Select Option. When I submit the view, the table should be filtered accordingly. Otherwise, all data should be displayed. However, my code is generating an error. No ...

Highcharts: single point muted and not easily seen when markers are turned off

Highchart displaying data with some null points (only visible via tooltip if marker disabled): https://i.stack.imgur.com/u04v1.png https://i.stack.imgur.com/uRtob.png Enabling markers will resolve the issue of invisible points, but it may look cluttered ...

Implementing an active state for the 'a' tag within Bootstrap 5 nav-tabs in an MVC application can be achieved by utilizing ActionLink

In my .NET MVC application, I am utilizing Bootstrap 5.1 to create navigation tabs with 'a' tags generated via ActionLink. <ul class="nav nav-tabs"> <li class="nav-item"> @Html.ActionLink("Enti ...

Increase the value only when there is existing code present

I currently have a MySQL table with two columns. The first column stores IP addresses, while the second column holds integers that need to be incremented. Whenever a new IP address visits the website, the integer associated with that IP should increase by ...

Creating a dynamic form in Angular based on user input

I am in the process of creating a dynamic web form where the user's input will determine the subsequent form inputs that are generated. For example: <mat-form-field> <mat-select placeholder="Type" [(ngModel)]="row.Type" (change)="Typ ...

Sort the parent by the number present in the child item using jQuery

Is there a way to rearrange a list of items based on a specific number within each item? Consider the following HTML structure that cannot be modified: <ul id="ul-list"> <li> <div class="name">product 1</div> & ...

Error: The background image is not displaying correctly on the .net webpage

I have included a link to an image but I am having trouble getting it to show up on my website. I even tried putting the image in a different folder, but still no luck with displaying it. Any assistance on this matter would be greatly appreciated. I hav ...

Tips for creating responsive headings in Bootstrap

I've recently been developing a bootstrap website and have encountered an issue with the heading (h1) size on smaller screens. While everything else scales properly, the heading remains fixed and ends up being too large for small screens. How can I ad ...

I rely on the angular-responsive-carousel library for my project, but unfortunately, I am unable to customize the arrow and dots

When it comes to CSS, I utilize ng deep style in Angular 10 to make changes for browser CSS. However, I am facing an issue where the problem is not being resolved by my CSS code. Here is a snippet of my code: > ::ngdeep .carousel-arrow { > b ...

The dropdown menu in codeigniter is not displaying the selected option

When using a drop-down button to select an option from the available choices, I encountered a problem where the selected option was not displayed in the box. Additionally, it only allowed me to make one selection. The data for the drop-down menu is retriev ...