-1

I want the result Like Microsoft Excell

Nay
  • 3
  • 2
  • I am understand, but please see the picture that I shared. This is different :( – Nay Apr 10 '19 at 03:43
  • I want two diagonal lines like the picture that I shared – Nay Apr 10 '19 at 03:46
  • is this possible to make it? – Nay Apr 10 '19 at 03:47
  • Have an you tried using an X image and setting it as the background and setting `background-size:100% 100%;`? – mullac Apr 10 '19 at 04:00
  • If you are willing, please answer and give examples of codes and images that you can share this will help me. I'm sorry, haven't tried it yet :( – Nay Apr 10 '19 at 04:04

1 Answers1

1

There are many options for implementing your task. One of them is pseudo-elements in absolute positioning. We stretch each pseudo-element over the entire area of ​​the parent cell and use the background property to draw a diagonal line. One pseudo-element from the upper left corner to the lower right, the second - from the lower left corner to the upper right. Regardless of the width or height of the cell - the lines will go from corner to corner. If you need the cell content to be on top of the lines, then you need to position it above the pseudo-elements using the z-index property.

HTML:

<table>
  <tr>
    <td class="cross">
      <span>Text</span>
    </td>
    <td>
      <span>Text</span>
    </td>
    <td class="cross">
      <span>Text</span>
    </td>
  </tr>
</table>

CSS:

td {
  border: 1px solid #222;
}

.cross span {
  position: relative;
  z-index: 2;
}

.cross {
  position: relative;
  width: 200px;
  height: 100px;
  text-align: center;
}

.cross:before,
.cross:after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

.cross:before {
  background: linear-gradient(to top right, transparent calc(50% - 1px), red 50%, transparent calc(50% + 1px) );
}

.cross:after {
  background: linear-gradient(to left top, transparent calc(50% - 1px), red 50%, transparent calc(50% + 1px) );
}

And an example:

https://codepen.io/anon/pen/WWRqra

Alex Shink
  • 176
  • 3
  • 7