Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

table cell with border-image

Tags:

html

css

I want to add border image to table cells, but it doesn't work ...or I'm doing sth wrong... Border width is visible, but image is missing. My jsFiddle is here, code:

.table-bordered > tbody > tr > td, .table-bordered > tbody > tr > th,  .table-bordered > thead > tr > td, .table-bordered > thead > tr > th {
    border: 0; /* reset */
    border-color: transparent;
    border-style: solid;
    border-width: 27px;
    border-image: url(http://www.w3.org/TR/css3-background/border.png) 27 fill repeat;
}

Border-image code is generated with border-image.com

Any ideas? Or border-image is simply unsupported for tables?

like image 873
long Avatar asked May 15 '15 13:05

long


People also ask

Can we apply border to a cell in a table?

Add or change the line colorClick the table or select the cells where you want to add or change borders. , and then click the line color that you want. , and then click the borders that you want.

How do you add a border to a table cell in HTML?

To create table border in HTML, the border attribute was used. But the introduction of HTML5, deprecated the border tag. Create table border using the CSS property border. Set table border as well as border for <th> and <td>.

How do you put a border inside a table?

There are two ways to apply border inside the table in HTML. Only Using HTML: In this case, we will use rules attribute of table. Rules is the attribute in HTML table which allows user to display only inside borders of the table which can be chosen among only rows, cols or all.

How do I add a border to a row in a table?

To add a border to your table, you need to define the <style> of your table. Remember to add borders also for <th> and <td> tags to have a complete table. Set the border-collapse property as well (if you don't define the border-collapse, it will use border-collapse: separate by default).


3 Answers

You've included bootstrap.min.css which is overriding your CSS.

Try this fiddle instead: https://jsfiddle.net/6025vyn9/

Edit: To clarify, border-image applies to tables (the outside of the table) but doesn't apply to internal table elements when border-collapse is collapse: http://www.w3.org/TR/css3-background/#the-border-image-source

like image 64
DigitalDan Avatar answered Nov 09 '22 04:11

DigitalDan


What about forgetting about styling the table and wrap elements in divs instead and then styling the divs like the snippet below. Then just tweak it with something like table td:not:(:last-of-type), table th:not(:last-of-type) and table tr:not(:last-of-type) to remove the double borders that appear by setting specific border sides to appear

.table-bordered div {
    text-align: center;
    padding:10px;
    border-color: transparent;
    border-style: solid;
    border-width: 27px;
    -moz-border-image: url(http://www.w3.org/TR/css3-background/border.png) 27 repeat;
    -webkit-border-image: url(http://www.w3.org/TR/css3-background/border.png) 27 repeat;
    -o-border-image: url(http://www.w3.org/TR/css3-background/border.png) 27 repeat;
    border-image: url(http://www.w3.org/TR/css3-background/border.png) 27 fill repeat;
}
.table-bordered * {
    border: 0;
}
<table class="table-bordered" cellspacing=0 cellpadding=0>
    <thead>
        <tr>
            <th>
                <div>Foo</div>
            </th>
            <th>
                <div>Bar</div>
            </th>
            <th>
                <div>Lols</div>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <div>something here</div>
            </td>
            <td>
                <div>whatever</div>
            </td>
            <td>
                <div>6,0% / 12% wag.</div>
            </td>
        </tr>
    </tbody>
</table>
like image 43
ctwheels Avatar answered Nov 09 '22 04:11

ctwheels


You have to separate the table border like this:

.table-bordered  {
    border-collapse:separate;
}

https://jsfiddle.net/2y3xqq0q/5/

http://www.w3.org/TR/CSS2/tables.html#borders

like image 23
Tom Marulak Avatar answered Nov 09 '22 05:11

Tom Marulak