Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

CSS Left border on table column group

Natrixx

New Coder
Hiya!

I have a table with some column groups. A couple of these groups span several columns. I'd like to have a left border on only the left-most column in a group like this. I tried

<col style="border-left: 1px solid;" span="2" >

but this results in both columns having a left border.

How should I write the css to achieve what I want?

Thanks in advance!

Mike
 
Please post the entire table code.

Does this work for you?
HTML:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Table Colgroup</title>

<style>
table {
    border-collapse: collapse;
}
th, td {
    border-bottom: 1px solid black;
}
colgroup {
    border-left: 6px solid black;
    background-color: red;
}
</style>
</head>
<body>
<h1>The Colgroup</h1>

<table id="collapsed">
    <colgroup>
        <col span="2">
        <col style="background-color: yellow">
    </colgroup>
    <tr>
        <th>ISBN</th>
        <th>Title</th>
        <th>Price</th>
    </tr>
    <tr>
        <td>3476896</td>
        <td>My first HTML</td>
        <td>$53</td>
    </tr>
    <tr>
        <td>5869207</td>
        <td>My first CSS</td>
        <td>$49</td>
    </tr>
</table>
</body>
</html>
 
Last edited by a moderator:

Buy us a coffee!

Back
Top Bottom