How can I apply a border only inside a table?

前端 未结 9 519
盖世英雄少女心
盖世英雄少女心 2020-11-30 17:24

I am trying to figure out how to add border only inside the table. When I do:

table {
    border: 0;
}
table td, table th {
    border: 1px solid black;
}
         


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 17:38

    this should work:

    table {
     border:0;
    }
    
    table td, table th {
        border: 1px solid black;
        border-collapse: collapse;
    }
    

    edit:

    i just tried it, no table border. but if i set a table border it is eliminated by the border-collapse.

    this is the testfile:

    
    
    
    
    
    
    Heading 1 Heading 2
    Cell (1,1) Cell (1,2)
    Cell (2,1) Cell (2,2)
    Cell (3,1) Cell (3,2)

提交回复
热议问题