How do I draw the green shape in the picture knowing that I have made attempts, but the table in the html does not allow me to form shapes in the cell
Here the output I want to achieve.
able{
font-family: arial, sans-sarif;
width: 90%;
border-collapse: collapse;
margin: 50px;
}
td,th{
border: 1px solid #ddd;
padding: 10px;
}
/* tr:nth-child(even){
background-color: #ddd;
} */
th{
background-color: #ddd;
}
.cent{
background: blue;
color: aqua;
width: 100%;
height: 100%;
}
<table>
<tr>
<th>Janvier</th>
<th>Fevrier</th>
<th>Mars</th>
<th>Avril</th>
<th>Mai</th>
<th>Juin</th>
</tr>
<tr>
<td>cc</td>
<td><span class="cent">cc</span></td>
<td style="min-width: 2em; background-color: RGB(0, 240, 0)">
</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
2
Answers
Note:
This answer uses the (relatively) new
:has()
relational pseudo-class in the selectors. Make sure it is supported well enough by your target browsers.Alternatively, select explicitly named classes for the individual segments (e.g.
.pill-shape
,.start-shape
,.mid-shape
,.end-shape
).The shape can be split into the following segments:
The
:has()
relational pseudo-class) can select elements based on its following elements (i.e. next siblings and children). The+
adjacent sibling combinator can select elements based on its immediately preceding sibling element.This means, by using the
:has()
pseudo-class and the+
combinator we can find out what shape (segment) a table cell<td>
should contain.Example:
After finding selectors that match our expectations, we can style the segments.
Example (which styles
::before
pseudo-elements for the segments):There’s already a best answer.
But if you needing an static css, i’ll leave you this scratch just in case.