css display:table not displaying the border

邮差的信 提交于 2019-12-02 18:40:52
dSquared

You need to add border-collapse: collapse; to the .table class for it to work like this:

<html>
<style type="text/css">
    .table   { display: table; border-collapse: collapse;}
    .tablerow  { display: table-row; border: 1px solid #000;}
    .tablecell { display: table-cell; }
</style>
<div class="table">
    <div class="tablerow">
        <div class="tablecell">Hello</div>
        <div class="tablecell">world</div>
    </div>
    <div class="tablerow">
        <div class="tablecell">foo</div>
        <div class="tablecell">bar</div>
    </div>
</div>
</html>

You need to add the border to the tablecell class.

Also, to make it look nice, you will need to add border-collapse:collapse; to the table class.

Example: http://jsfiddle.net/jasongennaro/4bvc2/

EDIT

As per the comment

i'm applying a border to a div,it should get displayed right ?

Yes, but once you set it to display as a table that is how it will act... as a table, so you will then need to follow the css rules for displaying tables.

If you need to set the border only on the rows, use border-top and border-bottom and then set specific classes for the leftmost and rightmost cells.

Table rows can't have a border attribute. You can get a border around each row by giving all cells a top and bottom border, and adding a class for the left-most and right-most cells with a left and right border respectively.

JS fiddle link

edit: I forgot about border-collapse:collapse. That will work too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!