CSS: How to make the column borders of the nth table thicker when the number of columns is variable?


Robert SF

enter image description here

I want to make the circled border thicker, but the number of columns can be between 3 and 6, and I can only use pure CSS (no Javascript, SASS or running CSS through PHP first). HTML is generated by PHP, but changing the PHP code to generate classes or inline styles is a last resort.

I tried using colgroupand col, but while it works , a col:first-child {border-right: 2px solid}thicker col:last-child {border-left: 2px solid}border is used on each column under Percentage.

Is there a way to make the bezel thicker given the above constraints?

As requested by dippas, below is the HTML code in question.

<table class="type1">
  <colgroup>
    <!-- note that "4" could range from 3 to 6 -->
    <col span="1">
    <col span="4">
    <col span="4">
  </colgroup>
  <thead>
    <tr>
      <th scope="row" rowspan="2">S = small M = medium L = large</th>
      <th scope="col" colspan="4">Responses</th>
      <th scope="col" colspan="4">Percentage</th>
    </tr>
    <tr>
      <th scope="col">S</th>
      <th scope="col">M</th>
      <th scope="col">L</th>
      <th scope="col">Tot</th>
      <th scope="col">S</th>
      <th scope="col">M</th>
      <th scope="col">L</th>
      <th scope="col">Tot</th>
    </tr>
  </thead>
  <tbody>
    <!-- following tr structure repeats for each question -->
    <!-- other questions have been removed for brevity -->
    <tr>
      <th scope="row">1. What size Coke do you prefer?</th>
      <td>24</td>
      <td><strong>28</strong></td>
      <td>0</td>
      <td>52</td>
      <td>46</td>
      <td><strong>54</strong></td>
      <td>0</td>
      <td>100</td>
    </tr>
  </tbody>
</table>

Note again that the number of columns is variable. In this case, the possible answers to the question are "Small, Medium, or Large," but it could be "1 to 5, and so on."

Rick Hitchcock

Here's a CSS-only solution that uses pseudo-elements to create borders that span the height of the table:

table {
  position: relative;
}

thead > tr:first-of-type th:not(:first-of-type)::after {
  content: '';
  position: absolute;
  display: block;
  top: 0;
  border: 2px solid black;
  height: calc(100% - 3px);
}

Suppose colspans are in the first row of the table in this theadsection - as in your example.

violin

Related


How to use css to make font thicker then 900

Gianluca I want to make the font extra bold due to the background color of my friend's image in the website header. I found it online, but unfortunately it doesn't work. Is there any other way? h1{ text-shadow: 1px 0 #888888; letter-spacing:1px; font-wei

CSS: How to remove borders for specific row/column in table

Gene I have the following table: I'm looking for a way to remove borders from "Row 1 - Column 1" cells, so it looks like this: Here is my html: <table id="tblContent" style="width:1000px;"> <tr> <td colspan="5">Row 1 - Column1</td> <td colspan="4"

How to make CSS borders on images?

Biggest Dredoff How can I crop an image (600х450) and create a border on it using CSS? Enter is it possible? What's better to use? Create some wrapper elements with border-radius? Andy Furniss I think this is the best way to use CSS: CSS: img { width:400px

How to make irregular CSS borders

Gibson I am trying to do this with CSS: It's easy to use a white background, but what if it has a background image? This is what I mean: I actually absolutely place the div inside another: <div class="main-div"> <div class="main-div-overlay-text"> SOME T

How to make pipes with borders in CSS

Rajish Frisky Maybe you are a little confused from the title above, but as the title says, I want to use CSS for this pipeline design , I think I can use CSS to achieve it, borderbut how do I add the circular bullet like in the image below? To simplify things,

How to make CSS borders on images?

Biggest Dredoff How can I crop an image (600х450) and create a border on it using CSS? Enter is it possible? What's better to use? Create some wrapper elements with border-radius? Andy Furniss I think this is the best way to use CSS: CSS: img { width:400px

How to make irregular CSS borders

Gibson I am trying to do this with CSS: It's easy to use a white background, but what if it has a background image? This is what I mean: I actually absolutely place the div inside another: <div class="main-div"> <div class="main-div-overlay-text"> SOME T

How to make irregular CSS borders

Gibson I am trying to do this with CSS: It's easy to use a white background, but what if it has a background image? This is what I mean: I actually absolutely place the div inside another: <div class="main-div"> <div class="main-div-overlay-text"> SOME T

How to make irregular CSS borders

Gibson I am trying to do this with CSS: It's easy to use a white background, but what if it has a background image? This is what I mean: I actually absolutely place the div inside another: <div class="main-div"> <div class="main-div-overlay-text"> SOME T

How to make pipes with borders in CSS

Rajish Frisky Maybe you are a little confused from the title above, but as the title says, I want to use CSS for this pipeline design , I think I can use CSS to achieve it, borderbut how do I add the circular bullet like in the image below? To simplify things,

How to make shapes with CSS with borders?

surrender thakran I'm looking for a way to make various geometric shapes using only HTML/CSS. I found the answer here , but it doesn't allow me to add a border to the shape. For example, I can use #triangle-down { width: 0; height: 0; border-left: 50px solid t

How to make shapes with CSS with borders?

surrender thakran I'm looking for a way to make various geometric shapes using only HTML/CSS. I found the answer here , but it doesn't allow me to add a border to the shape. For example, I can use #triangle-down { width: 0; height: 0; border-left: 50px solid t

How to make pipes with borders in CSS

Rajish Frisky Maybe you are a little confused from the title above, but as the title says, I want to use CSS for this pipeline design , I think I can use CSS to achieve it, borderbut how do I add the circular bullet like in the image below? To simplify things,

How to make CSS borders on images?

Biggest Dredoff How can I crop an image (600х450) and create a border on it using CSS? Enter is it possible? What's better to use? Create some wrapper elements with border-radius? Andy Furniss I think this is the best way to use CSS: CSS: img { width:400px

How to make irregular CSS borders

Gibson I am trying to do this with CSS: It's easy to use a white background, but what if it has a background image? This is what I mean: I actually absolutely place the div inside another: <div class="main-div"> <div class="main-div-overlay-text"> SOME T

How to make irregular CSS borders

Gibson I am trying to do this with CSS: It's easy to use a white background, but what if it has a background image? This is what I mean: I actually absolutely place the div inside another: <div class="main-div"> <div class="main-div-overlay-text"> SOME T

How to make CSS borders on images?

Biggest Dredoff How can I crop an image (600х450) and create a border on it using CSS? Enter is it possible? What's better to use? Create some wrapper elements with border-radius? Andy Furniss I think this is the best way to use CSS: CSS: img { width:400px

How to make irregular CSS borders

Gibson I am trying to do this with CSS: It's easy to use a white background, but what if it has a background image? This is what I mean: I actually absolutely place the div inside another: <div class="main-div"> <div class="main-div-overlay-text"> SOME T

How to make irregular CSS borders

Gibson I am trying to do this with CSS: It's easy to use a white background, but what if it has a background image? This is what I mean: I actually absolutely place the div inside another: <div class="main-div"> <div class="main-div-overlay-text"> SOME T

How to make pipes with borders in CSS

Rajish Frisky Maybe you are a little confused from the title above, but as the title says, I want to use CSS for this pipeline design , I think I can use CSS to achieve it, borderbut how do I add the circular bullet like in the image below? To simplify things,

How to make table cell borders cover neighbor table cell borders

L. So in the example below you will see that the black border only covers the bottom and right side, while I want it to cover the left and top as well. Is there a way to fix this? table { border-collapse: collapse; } table td { border: 1px solid red; he

How to make table cell borders cover neighbor table cell borders

L. So in the example below you will see that the black border only covers the bottom and right side, while I want it to cover the left and top as well. Is there a way to fix this? table { border-collapse: collapse; } table td { border: 1px solid red; he

How to make a plane thicker in RGL?

what for I'll try to make some nice visual illustrations for the binary classification example using the 3D printed data. Here is my 3D plot: require(rgl) #Get example data from mtcars and normalize to range 0:1 fun_norm <- function(k){(k-min(k))/(max(k)-min(k