CSS Table Border

Example tables

A few examples. Padding is ommitted for clarity. See also the examples with alternative syntax.

Corresponds to HTML3 rule=all, border=1.

The second example from the HTML3 spec. (interpreted from the ASCII graphics).

table < border-top: double; border-bottom: double; border-right: blank >thead, tbody, tfoot < border-top: solid; border-bottom: solid >colgroup

A table with only vertical rules.

A table with only vertical rules between the columns.

A typical Netscape table: border=5, cellspacing=10.

NB1. 16 = 5 pixel border + 10 pixel spacing + 1 pixel shadow. Similarly, 12 = 10 px spacing + 2 shadows.

NB2. It is convenient in this case to specify the ridge as 1,10,1, which sums to 12, but 2,20,2 would have given exactly the same result.

A complex table head, but no rules in the body.

thead < border-top: solid thick; border-right: blank; /* prevent colgroup border */ border-left: blank /* prevent cell border */ >colgroup < border-right: solid thick >thead td < border: solid >tbody td < border: blank >/* remove colgroup border */ >

This example is complicated because there is no way to address the part of the colgroup in the thead. It seems we would need a sort intersection operator for that. The problem has been solved in this case by setting the border on the whole colgroup and then removing it again in the tbody.

Chris Wilson’s example 1, in his notation:

Assuming that `thin’ means 1px (not too unlikely), the table’s border will be 2px shadow + 1px padding + 1px margin + 1 px shadow = 5px. Note that I also assume that shadow colors are chosen automatically.

Chris Wilson’s example 2. In his notation:

Note that there are other ways of specifying the same. Instead of border on TR, one could have set top and bottom on each cell.

Chris Wilson’s example 3. In his notation:

Chris Wilson’s example 4. In his notation:

The shadow part seems to stick out, instead of being inside the border. That means it can overlap something else, but maybe that is a good thing. How about adding a transparency to the shadow? Here is an example style sheet:

Cell G is assumed to have an ID `G’. The keyword `override’ is used to make sure the cell’s border style is honoured. If drop shadows are always `stronger’ than dots, this keyword can be omitted.

The color difference between the border and the cell is a problem. It can be solved in several ways: (1) in HTML, by putting the cell content inside another element, such as a P or DIV and putting a background on that, or (2) introducing a border-background property, or (3) specyfing that the table background is used for the border background.

Solution 1 doesn’t work if the child elements have unequal height. With solution 2 and 3, the dotted style needs the extra parameter that was already suggested earlier, to set the dot’s diameter.

Using solution 2 (set the yellow on child elements of the cells):

Using solution 3 (table background is used for borders):

The problem here is the short red borders. It seems necessary to introduce the short rules as border types. Note that the endpoints of the rules are not aligned with the text, although that is more common in other tables.

Also the white lines seem to go underneath the green dots, but this could be a general rule any time a solid line and a dotted line cross.

An attempt using Dave’s model:

An attempt using my model:

Diagonal text and diagonal borders cannot be done without introducing some new property. Note that the cells are sheared 30°, while the text is put vertically as well.

There are several ways of looking at this table: (1) is is actually two tables instead of one, (2) there is space between the head and the body, (3) between the head and the body is a double line.

Using 3 (and assuming the border background is taken from the table background):

tr < border: .4pt >table < border: thick solid >thead < border: 14pt double(1,12,1) >thead < background: cyan >tr.odd < background: yellow >tr.even

Short horizontal rules between the cells.

td, th < border-bottom: thin short >table < border: none >/* remove bottom border */

The default for `short’ can be the cell’s padding.

Single black border in the body, white (or transparent) borders in the head. (Actually, in the original, the blue parts weren’t really aligned, they seemed to have been placed by an unsteady hand.) Bert Bos
19 April 1996

Источник

HTML Table Borders

HTML tables can have borders of different styles and shapes.

How To Add a Border

To add a border, use the CSS border property on table , th , and td elements:

Example

Collapsed Table Borders

To avoid having double borders like in the example above, set the CSS border-collapse property to collapse .

This will make the borders collapse into a single border:

Example

Style Table Borders

If you set a background color of each cell, and give the border a white color (the same as the document background), you get the impression of an invisible border:

Example

table, th, td <
border: 1px solid white;
border-collapse: collapse;
>
th, td <
background-color: #96D4D4;
>

Round Table Borders

With the border-radius property, the borders get rounded corners:

Example

Skip the border around the table by leaving out table from the css selector:

Example

Dotted Table Borders

With the border-style property, you can set the appearance of the border.

The following values are allowed:

Example

Border Color

With the border-color property, you can set the color of the border.

Example

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

Руководство CSS Tables

Следуйте за нами на нашей фан-странице, чтобы получать уведомления каждый раз, когда появляются новые статьи. Facebook

1- Table borders

В основном, у таблицы имеется 2 вида границы (border) это граница таблицы и граница ячеек, как в изображении ниже:

По умолчанию соседние ячейки не используют одну границу, а имеют отдельные. Так же граница таблицы отделяется от границы ячеек.

      .table1 < border: 1px solid red; >.table1 th < border: 1px solid blue; padding: 5px; >.table1 td 

HTML Table Boder

First Name Last Name
John Smith

CSS border-spacing применяется для чтобы определить расстояние между границами соседних ячеек.

 /* */ border-spacing: 2px; /* horizontal | vertical */ border-spacing: 1cm 2em; /* Global values */ border-spacing: inherit; border-spacing: initial; border-spacing: unset; 

      .table1 < border: 1px solid red; border-spacing: 40px; >.table1 th < border: 1px solid blue; padding: 25px; >.table1 td 

HTML Table Boder-spacing

First Name Last Name
John Smith

2- Collapsed Table borders

Используйте CSS border-collapse:collapse для таблицы, если вы хотите чтобы соседние ячейки использовали одну границу, и одну границу с таблицей. Значение по умолчанию у CSS border-collapse является separate.

Так как каждая ячейка может использовать свой стиль границы (border style). Таким образом для свернутых таблиц (Collapsed table) произойдет конфликтная ситуация, потому чт 2 соседние ячейки используют одну границу. Вопрос здесь в том, какой стиль будет использоваться в случае конфликта?

Примечание: CSS border-style:none и CSS border-style:hidden одинаковы, лишают элементы границ. Отличаются только при применении к свернутой таблице (Collapsed table). При решении конфликта, CSS border-style:hidden имеет самый высокий приоритет, при этом CSS border-style:none имеет самый низкий приоритет.

      table < border-collapse: collapse; border: 1px solid black; >th, td 

CSS Collapsed Table

border-style:solid;
border-width:1px;
border-color:blue;
border-style:dashed;
border-width:1px;
border-color:red;
border-style:hidden;
border-width:1px;
border-color:green;
border-style:none;
border-width:1px;
border-color:green;

3- CSS Table Width/Height

Свойство CSS width, CSS height используется для установки ширины и высоты для таблицы, или строки (row), или столбцы (column).

Примечание: Некоторые браузеры считают , , только контейнерами (container), поэтому CSS height не работает когда вы применяете к нему данные элементы. Если вы хотите настроить высоту для строки (row) таблицы, вам нужно применить CSS height к или .

В таблице имеется много столбцов, они пронумерованы 1, 2, . Используйте CSS th:nth-child(N) для применения стиля к N-ному столбцу таблицы.

Например: Таблица с 3-мя столбцами, установите width:40% для 2-х первых столбцов и width:20% для 3-го столбца.

 table < width: 100%; border-collapse: collapse; border: 1px solid black; >th:th:nth-child(1), th:th:nth-child(2) < width: 40%; >th:th:nth-child(3) < width: 20%; >th, td

View more Tutorials:

Это онлайн курс вне вебсайта o7planning, который мы представляем, он включает бесплатные курсы или курсы со скидкой.

  • * * Write quicker HTML5 and CSS 3; productivity hacks with emmet
  • Learning CSS
  • HTML5, CSS3 & JavaScript Workshop: Build 7 Creative Projects
  • HTML 5 and CSS 3 — tricks and workarounds
  • Ultimate HTML and CSS course for Absolute Beginners 2015
  • HTML CSS JavaScript: Most popular ways to code HTML CSS JS
  • CSS3 Master Series: CSS Animations, Transforms & Transitions
  • CSS Development (with CSS3!)
  • Web Design for Beginners: Real World Coding in HTML & CSS
  • A Web Development Crash Course in HTML5 and CSS3
  • Create Beautiful Websites with CSS3
  • * * Master the Basics of HTML5 & CSS3: Beginner Web Development
  • Mastering CSS3 Colors
  • * * Beginner Photoshop to HTML5 and CSS3
  • CSS3 MasterClass — Transformations And Animations
  • CSS and CSS3 Advanced
  • * * Mastering CSS 3.0 Selectors
  • CSS3: Video QuickStart Guide
  • Изучите HTML и CSS за несколько часов
  • Learn Html5 & CSS3 from scratch
  • Step-by-step HTML and CSS for Absolute Beginners
  • HTML5 and CSS for Beginner To Expert
  • Create Android and iOS App using HTML, CSS and JS
  • Build Real World Websites from Scratch using HTML5 and CSS3
  • HTML CSS Easy steps to create a web template from scratch

Источник

CSS – How to Completely Remove Borders From HTML Table

The table is a major component of the HTML page used to store and organize the data. Developers can design the HTML table using CSS properties, such as background color, border, margin, padding, etc. The CSS “border” property is utilized to set borders around tables and cells. But, in some scenarios, users do not require a border for styling.

This post will explain how to remove borders from HTML using CSS completely.

How to Completely Remove Borders From HTML Table?

If users want to remove borders completely from an HTML table, look at the instructions.

Step 1: Create Table With Border

To create a table in HTML, follow the instructions:

  • First, add a table element “ ” along with the “border” attribute.
  • Then, the “ ” tag is added to create the desired number of rows.
  • The heading cells are specified using “ ” tags.
  • After that, “ ” tags are included in other “ ” tags for adding data cells:

For styling the HTML table, we will use following CSS properties:

  • margin” property with the value “auto” is used to set equal space around the element.
  • padding” property with the value “10px” sets the space of 10px around the element’s content.
  • border” property applies the border around the table.

Step 2: Remove Border in CSS

To remove the border from the table, users are required to set the “border” property as “none”:

It can be observed that the outer border from the table has been removed successfully:

Step 3: Completely Remove Table border

Furthermore, if you want to remove the entire border from the table as well as from cells, set “border” property as “none” on all elements, including “table”, “tr”, “th”, and “td”:

The below output indicates that we have completely removed the border from the HTML table:

We have demonstrated the method to remove borders from HTML tables completely.

Conclusion

To completely remove the border from the HTML table, first create a table. After that, apply CSS properties “border”, “padding”, and “margin” on the table. Then, set the border property as “none” on all table elements, such as “table”, “tr”, “td”, and “th”. This tutorial has demonstrated the method for completely removing the border from the HTML table.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.

Источник

Читайте также:  Xml to csv in javascript
Оцените статью