0

Our online store has a variations table with prices. The cells display the original price, the sale price, and the discount percentage. We use this script to get the discount.

Since the prices are the same in all variations, the client wants the discount percentage figure to appear highlighted only once outside the table instead of repeated in each price cell for two reasons: better visibility and reduce visual noise on the prices.

The problem:

The percentage figure is displayed correctly when there's only one price as can be seen in Table 2.

But as the number of variations grows, the font smoothing disappears by showing the percentages of each price overlaid Table 1. It obviously gets worse as the number of variations and prices increase.

We have tried to solve it from the style sheet with :not(first-child) to hide the percentage of all cells below the first with no result.

Any alternative solution?

Note: the figures and percentages in the examples are not the real ones

variations table

.products .snippet-dto-porcentaje {
  display: none;
}

.product .snippet-dto-porcentaje {
  position: absolute;
  top: 2rem;
  right: 3rem;
  font-size: 7rem;
  font-family: 'Helvetica', sans-serif;
  color: #000000;
  border-radius: 5rem;
  padding: 1rem;
}

table.vartable {
  border-collapse: collapse;
  width: fit-content;
  margin: 2rem 0 4rem;
}

table.vartable>thead>tr>th {
  border: 2px;
  border-style: solid;
  border-color: gray;
  color: white;
  background-color: gray;
  text-align: center;
}

table.vartable td {
  border: 2px;
  border-style: solid;
  border-color: gray;
  text-align: center;
  padding: 0 3rem;
}

table.vartable td.pricecol {
  padding: 0 1.75rem;
}

td.pricecol>del {
  padding-right: 1.75rem;
}

td.pricecol>ins>span>bdi {
  padding-left: 1.75rem;
}

td.pricecol>ins>span>bdi:before {
  content: "|";
  margin-left: -2rem;
  font-size: 3rem;
  color: gray;
  line-height: 0%;
  position: absolute;
  transform: scale(0.5, 0.6);
  margin-top: 0.7rem
}
<div class="product">
  <table class="table vartable">

    <thead>
      <tr>
        <th>TABLE 1</th>
      </tr>
    </thead>

    <tbody>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>


      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>


      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

    </tbody>
  </table>


  <table class="table vartable">

    <thead>
      <tr>
        <th>TABLE 2</th>
      </tr>
    </thead>

    <tbody>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje" style="top:14rem;">30%</span>
        </td>
      </tr>

    </tbody>
  </table>

</div>
aynber
  • 22,380
  • 8
  • 50
  • 63
Danielillo
  • 247
  • 2
  • 14
  • Please show your attempt using `:not(first-child)`. – 0stone0 May 23 '22 at 09:57
  • I hope it's already clear to you that you have several `div.snippet-dto-porcentaje` with position absolute all in the same exact spot and that's causing that loss of smoothing. A very very quick solution would be to add a background (even white) to that rule (`.product .snippet-dto-porcentaje`). Anyway it's not only a matter of styles here. I would surely better deal with that repetitions and honestly is not clear which one should win there. – Diego D May 23 '22 at 10:04

3 Answers3

1

You can set the text-shadow of the percentage to white to conceal the things behind it.

.products .snippet-dto-porcentaje {
  display: none;
}

.product .snippet-dto-porcentaje {
  position: absolute;
  top: 2rem;
  right: 3rem;
  font-size: 7rem;
  font-family: 'Helvetica', sans-serif;
  color: #000000;
  border-radius: 5rem;
  padding: 1rem;
  text-shadow: 0px 0px 2px white;
}

table.vartable {
  border-collapse: collapse;
  width: fit-content;
  margin: 2rem 0 4rem;
}

table.vartable>thead>tr>th {
  border: 2px;
  border-style: solid;
  border-color: gray;
  color: white;
  background-color: gray;
  text-align: center;
}

table.vartable td {
  border: 2px;
  border-style: solid;
  border-color: gray;
  text-align: center;
  padding: 0 3rem;
}

table.vartable td.pricecol {
  padding: 0 1.75rem;
}

td.pricecol>del {
  padding-right: 1.75rem;
}

td.pricecol>ins>span>bdi {
  padding-left: 1.75rem;
}

td.pricecol>ins>span>bdi:before {
  content: "|";
  margin-left: -2rem;
  font-size: 3rem;
  color: gray;
  line-height: 0%;
  position: absolute;
  transform: scale(0.5, 0.6);
  margin-top: 0.7rem
}
<div class="product">
  <table class="table vartable">

    <thead>
      <tr>
        <th>TABLE 1</th>
      </tr>
    </thead>

    <tbody>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>


      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>


      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
        </td>
      </tr>

    </tbody>
  </table>


  <table class="table vartable">

    <thead>
      <tr>
        <th>TABLE 2</th>
      </tr>
    </thead>

    <tbody>

      <tr>
        <td class="pricecol" data-label="Precio">
          <del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje" style="top:14rem;">30%</span>
        </td>
      </tr>

    </tbody>
  </table>

</div>
0

Since you want the td's to be hidden, but only the first row, you'll need a css selector like:

table > tbody > tr:not(:first-of-type) > td {
    display: none;
}

So get the not first row, and the td inside.

.products .snippet-dto-porcentaje {display:none;}

.product .snippet-dto-porcentaje {
position:absolute;
top:2rem; right:3rem;
font-size:7rem;
font-family: 'Helvetica', sans-serif;
color:#000000;
border-radius: 5rem;
padding:1rem;

}

table > tbody > tr:not(:first-of-type) > td {
  display: none;
}

table.vartable {border-collapse: collapse;
width: fit-content;
margin: 2rem 0 4rem;}

table.vartable > thead >tr>th {
    border: 2px;
    border-style: solid;
    border-color: gray;
    color: white;
    background-color: gray;
    text-align: center;}

table.vartable td {
border: 2px;
border-style: solid;
border-color: gray;
text-align:center;
padding:0 3rem;
}


table.vartable td.pricecol{padding:0 1.75rem;}

td.pricecol > del {padding-right: 1.75rem;  
}

td.pricecol > ins > span > bdi {padding-left: 1.75rem;}

td.pricecol > ins > span > bdi:before {content:"|"; 
    margin-left:-2rem; 
    font-size:3rem; 
    color: gray; 
    line-height: 0%; 
    position: absolute;
transform: scale(0.5, 0.6);
margin-top:0.7rem}
<div class="product">
<table class="table vartable">

<thead>
<tr>
<th>TABLE 1</th>
</tr>
</thead>

<tbody>

<tr>
<td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
</td>
</tr>
          
<tr>
<td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
</td>
</tr>
          
<tr>
 <td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
</td>
</tr>

<tr>
 <td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
</td>
</tr>

<tr>
 <td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
</td>
</tr>


<tr>
 <td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
</td>
</tr>


<tr>
 <td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
</td>
</tr>

<tr>
 <td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje">30%</span>
</td>
</tr>

</tbody>
</table>


<table class="table vartable">

<thead>
<tr>
<th>TABLE 2</th>
</tr>
</thead>

<tbody>

<tr>
<td class="pricecol" data-label="Precio">
<del aria-hidden="true"><span><bdi>12,00&nbsp;&euro;</bdi></span></del> <ins><span><bdi>10,20&nbsp;&euro;</bdi></span></ins><span class="snippet-dto-porcentaje" style="top:14rem;">30%</span>
</td>
</tr>
          
</tbody>
</table>

</div>
0stone0
  • 34,288
  • 4
  • 39
  • 64
  • I don't want to hide any cell, just the content of the discount column except the first cell. This answer is exactly the same as having just one price. – Danielillo May 23 '22 at 10:13
0

I found the solution by adapting this answer

   .vartable tr:not(:first-child) .snippet-dto-porcentaje {display:none;}
Danielillo
  • 247
  • 2
  • 14