Home Web Front-end CSS Tutorial Use css to set the border of the table and consider compatibility

Use css to set the border of the table and consider compatibility

Nov 24, 2016 am 10:42 AM
css

Table is a good tag for displaying data on web pages. By default, the table does not have a border, but for the sake of good appearance, we often add a border to the table. Moreover, the border color under IE7/8/9 is different. Let’s take a look at how to use css to control the display of the table border.
First, we create a simple table, the code is as follows:
[html]


                                                                                                ;first row
                                                                
table>
The initial style is very simple:
[css]
.my-table {
border: 1px solid #ccc;
}
At this time, the table behaves almost the same in each browser. I chose the screenshot under chrome




At this time, if we need to add border to each line, what should we do? If you are smart, you should have thought of the tr tag. Yes, let’s give it a try and rewrite the css as follows:
[css] .my-table {

border: 1px solid #ccc; Use css to set the border of the table and consider compatibility}

.my-table tr {

Border: 1px solid blue;
}
Then refresh the page, unfortunately, nothing happens. Note that writing border above tr has no effect. So, let’s try the td tag again, maybe there will be surprises. Rewrite the css as follows:
[css]
.my-table {
  border: 1px solid #ccc;
}
.my-table td {
  border : 1px solid blue;
}
Now we can see new changes. The performance of each browser is basically the same, but the fly in the ointment is that there are spaces between the borders of td:




For the sake of beauty, we have to Remove the space between cells, use border-collapase:collapase, and rewrite the css as follows:
[css]

.my-table {

border: 1px solid #ccc; Use css to set the border of the table and consider compatibility border-collapse: collapse;

}

.my- table td {
  border: 1px solid blue;
}
Let’s see what the table looks like now, the performance is different in different browsers. We can see from the picture below that under chrome and FF, the border of td will replace the border outside the table, while the outer frame of the table under IE has not changed. Next time, it will be more obvious to use a brighter color to mark it.





So, how can we achieve consensus? I found that if the width of the outer border of the table is increased, it is ok; strictly speaking, one should follow this rule: compare the width of the outer border with the width of the td, whichever is wider will display the border.

For example, I set the border width of table and td to 2px and 1px respectively, and then set a border width of 5px and 4px for comparison (note that I have changed the color to be more eye-catching)

Use css to set the border of the table and consider compatibilityUse css to set the border of the table and consider compatibility


In fact, through experiments We found that at this time, the performance of the table was consistent across all browsers. When writing CSS, you can use the above code to ensure compatibility with most browsers, including IE6.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does placeholder mean in vue What does placeholder mean in vue May 07, 2024 am 09:57 AM

What does placeholder mean in vue

How to write spaces in vue How to write spaces in vue Apr 30, 2024 am 05:42 AM

How to write spaces in vue

How to get dom in vue How to get dom in vue Apr 30, 2024 am 05:36 AM

How to get dom in vue

What does span mean in js What does span mean in js May 06, 2024 am 11:42 AM

What does span mean in js

What does rem mean in js What does rem mean in js May 06, 2024 am 11:30 AM

What does rem mean in js

How to introduce images into vue How to introduce images into vue May 02, 2024 pm 10:48 PM

How to introduce images into vue

What is the function of span tag What is the function of span tag Apr 30, 2024 pm 01:54 PM

What is the function of span tag

How to wrap prompt in js How to wrap prompt in js May 01, 2024 am 06:24 AM

How to wrap prompt in js

See all articles