Css spacing between rows in table

CSS Spacing in a html table between rows

The following tutorial shows you how to use CSS to do «CSS Spacing in a html table between rows».

CSS Style

The CSS style to do «CSS Spacing in a html table between rows» is

.table !-- w w w . d e m o 2 s . c o m --> font-size:18px; border-spacing:0 10px; display:table; width:100%; > .row-group < display:table-row-group; width:100%; border:10px solid black; > .row-group::after < content:"\00a0"; > .row < display:table-row; > .cell < display:table-cell; width:35%; > .right < text-align:right; > .center < text-align:center; > div.header < background-color:rgba(200,255,100,.9); background-color:yellow; font-weight:bold; > .team < background-color:gray; > .cell>p < margin:10px; >

HTML Body

body> div >"content content1"> div >"table"> div >"row-group"> div >"row header"> div >"cell"> p> 18:00:00  div >"cell">  div >"cell right"> p> A   !-- ww w . d e m o 2 s . c o m --> div >"row"> div >"cell team"> p> Team 1  div >"cell center"> p> :  div >"cell right team"> p> Team 2    div >"row-group"> div >"row header"> div >"cell"> p> 18:00:00  div >"cell">  div >"cell right"> p> C   div >"row"> div >"cell team"> p> Team 3  div >"cell center"> p> :  div >"cell right team"> p> Team 4    div >"row-group"> div >"row header"> div >"cell"> p> 18:14:00  div >"cell">  div >"cell right"> p> A    div >"row"> div >"cell team"> p> Team 5  div >"cell center"> p> :  div >"cell right team"> p> Team 6       

The following iframe shows the result. You can view the full source code and open it in another tab.

html> head> meta name="viewport" content="width=device-width, initial-scale=1"> style id="compiled-css" type="text/css"> .table !-- w w w .d e m o 2 s . co m--> font-size: 18px; border-spacing: 0 10px; display: table; width: 100%; > .row-group < display: table-row-group; width: 100%; border: 10px solid black; > .row-group::after < content: "\00a0"; > .row < display: table-row; > .cell < display: table-cell; width: 35%; > .right < text-align: right; > .center < text-align: center; > div.header < background-color: rgba(200,255,100,.9); background-color: yellow; font-weight: bold; > .team < background-color: gray; > .cell>p< margin: 10px; >  body> div >"content content1"> div >"table">div >"row-group">div >"row header"> div >"cell">p> 18:00:00  div >"cell">  div >"cell right">p> A   div >"row"> div >"cell team">p> Team 1  div >"cell center">p> :  div >"cell right team">p> Team 2   div >"row-group">div >"row header"> div >"cell">p> 18:00:00  div >"cell">  div >"cell right">p> C  div >"row"> div >"cell team">p> Team 3  div >"cell center">p> :  div >"cell right team">p> Team 4   div >"row-group">div >"row header"> div >"cell">p> 18:14:00  div >"cell">  div >"cell right">p> A   div >"row"> div >"cell team">p> Team 5  div >"cell center">p> :  div >"cell right team">p> Team 6        

  • CSS Skipping rows in HTML Table
  • CSS slideToggle in table row
  • CSS slideToggle in table row (Demo 2)
  • CSS Spacing in a html table between rows
  • CSS Spacing in a html table between rows (Demo 2)
  • CSS Spacing in a html table between rows (Demo 3)
  • CSS Spacing in a html table between rows (Demo 4)

demo2s.com | Email: | Demo Source and Support. All rights reserved.

Источник

How to Add Space Between Rows in the Table

Today’s task is to create space between two rows in a table. The space between two rows in a can be added by using the CSS border-spacing and border-collapse properties. The border-spacing property is used to set the spaces between cells of a table , and the border-collapse property specifies whether the border of the table is collapsed or not. The border-spacing property can be used only when the border-collapse property is set to «separate».

Let’s see an example and show how to do that step by step.

Create HTML

body> div> h2>W3docsh2> h3>Row spacing in a tableh3> table> tr> th>Employee IDth> th>Nameth> th>Genderth> th>Ageth> tr> tr> td >td">10001td> td>Tomtd> td>Mtd> td>30td> tr> tr> td >td">10002td> td>Sallytd> td>Ftd> td>28td> tr> tr> td >td">10003td> td>Emmatd> td>Ftd> td>24td> tr> table> div> body>

Add CSS

  • Use the border-collapse property with its «separate» value for the table.
  • Use the border-spacing property to set the distance between the borders of neighbouring table cells.
  • For the first row, set the background color and the color of the text by using the background-color and color properties.
  • Set the width and padding of the rows.
  • Use the text-align property with the «center» value which aligns the text to the center.
  • You can create a border around the cells of the table by using the border property and use the border-width, border-style and border-color properties.
  • You can set the color of the element of the document by using the color property. Also, you can choose any color from our color picker.
table < border-collapse: separate; border-spacing: 0 15px; > th < background-color: #4287f5; color: white; > th, td < width: 150px; text-align: center; border: 1px solid black; padding: 5px; > h2 < color: #4287f5; >

Here is the result of our code.

Example of adding space between horizontal rows:

html> html> head> title>Title of the document title> style> table < border-collapse: separate; border-spacing: 0 15px; > th < background-color: #4287f5; color: white; > th, td < width: 150px; text-align: center; border: 1px solid black; padding: 5px; > h2 < color: #4287f5; > style> head> body> div> h2>W3docs h2> h3>Row spacing in a table h3> table> tr> th>Employee ID th> th>Name th> th>Gender th> th>Age th> tr> tr> td class="td">10001 td> td>Tom td> td>M td> td>30 td> tr> tr> td class="td">10002 td> td>Sally td> td>F td> td>28 td> tr> tr> td class="td">10003 td> td>Emma td> td>F td> td>24 td> tr> table> div> body> html>

Result

Row spacing in a table

Employee ID Name Gender Age
10001 Tom M 30
10002 Sally F 28
10003 Emma F 24

Example of adding space between vertical columns:

html> html> head> title>Title of the document title> style> table < border-collapse: separate; border-spacing: 20px 0; > th < background-color: #4287f5; color: white; > th, td < width: 150px; text-align: center; border: 1px solid black; padding: 5px; > h2 < color: #4287f5; > style> head> body> div> h2>W3docs h2> h3>Row spacing in a table h3> table> tr> th>Employee ID th> th>Name th> th>Gender th> th>Age th> tr> tr> td class="td">10001 td> td>Tom td> td>M td> td>30 td> tr> tr> td class="td">10002 td> td>Sally td> td>F td> td>28 td> tr> tr> td class="td">10003 td> td>Emma td> td>F td> td>24 td> tr> table> div> body> html>

In our first example, for the border-spacing property, we use a «0 15px» value which means that space is between the horizontal rows. In the second example, we use a «20px 0 » value which means that space is between the vertical rows.

A problem?!

Let’s give some background to our table to see what we’re talking about, so:

table < border-collapse: separate; border-spacing: 20px 0; background: khaki; /* add this line */ >

row-spacing-in-tables

What if we want inner borders to be removed between the columns in this example? Now we have it in outer space of Employee ID and Age columns.

Ok, let’s fix this together!

Remove the border-collapse: separate and border-spacing: 20px 0 from the table CSS.

Now, we will add the border-spacing: 20px 0 on each td of our table, instead of the whole table.

We should also add a display property of the block to have it work the way we want it to.

So, our changes would be like this:

table < background: khaki; > table tbody < display: block; border-spacing: 20px 0; >

The result will be the same as before. Now, its’ time for us to delete the left and right outer border space. It can be done quickly by just adding the negative margin to the left and right of each td element so that it will remove that space for us.

table < background: khaki; > table tbody < margin: 0 -20px; /* add this line, -20px margin to left and right, 20px is based on the border-spacing amount which is 20 px in this example */ display: block; border-spacing: 20px 0; >

And here we go! This is precisely what we wanted! As you see, the left and right outer space have gone for good!

row-spacing-in-tables-2

Now you can remove the background color as well and have your beautiful table!

Hope you enjoyed it, have a good time!

Источник

Css spacing between rows in table

Learn Latest Tutorials

Splunk tutorial

SPSS tutorial

Swagger tutorial

T-SQL tutorial

Tumblr tutorial

React tutorial

Regex tutorial

Reinforcement learning tutorial

R Programming tutorial

RxJS tutorial

React Native tutorial

Python Design Patterns

Python Pillow tutorial

Python Turtle tutorial

Keras tutorial

Preparation

Aptitude

Logical Reasoning

Verbal Ability

Company Interview Questions

Artificial Intelligence

AWS Tutorial

Selenium tutorial

Cloud Computing

Hadoop tutorial

ReactJS Tutorial

Data Science Tutorial

Angular 7 Tutorial

Blockchain Tutorial

Git Tutorial

Machine Learning Tutorial

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures tutorial

DAA tutorial

Operating System

Computer Network tutorial

Compiler Design tutorial

Computer Organization and Architecture

Discrete Mathematics Tutorial

Ethical Hacking

Computer Graphics Tutorial

Software Engineering

html tutorial

Cyber Security tutorial

Automata Tutorial

C Language tutorial

C++ tutorial

Java tutorial

.Net Framework tutorial

Python tutorial

List of Programs

Control Systems tutorial

Data Mining Tutorial

Data Warehouse Tutorial

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • WordPress
  • Graphic Designing
  • Logo
  • Digital Marketing
  • On Page and Off Page SEO
  • PPC
  • Content Development
  • Corporate Training
  • Classroom and Online Training
  • Data Entry

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Источник

Css how to add spacing between table rows

Solution 3: Add following rule to tr and it should work Sample (Open it in IE9 offcourse 🙂 ): http://jsfiddle.net/zshmN/ Solution 1: Solution 2: Use and to add vertical magin only.

Space between CSS Table Rows

Use border-spacing to create the spacing.

And if you want the gaps to have no background color, move the background-color from the table to the table-rows.

.live-mu-table < display: table; margin-bottom: 5px; padding-bottom: 5px; position: relative; margin-left: auto; margin-right: auto; width: 75%; border-spacing: 0 3px; /* new */ >.live-mu-table-tr < display: table-row; height: 30px; background-color: Azure; /* moved */ >.live-mu-table-tdq < display: table-cell; border: 1px solid #000; width: 60%; text-align: center; vertical-align: middle; cursor: pointer; >.live-mu-table-tda < display: table-cell; border: 1px solid #000; width: 30%; text-align: center; vertical-align: middle; cursor: pointer; >.live-mu-table-tdspacer1

Css — Borders and spacing between specific table rows, A table with one header row and multiple body rows; A solid border under the header row; Vertical white space (padding? margin? spacing?) between the header row and first body row only; Body rows being highlighted on mouse hover. I couldn’t get (2) to be visible until I styled the table border-collapse: …

How to add space in between two tr or rows

I think you want like this:

table < border-collapse: collapse; >table tr td < padding:5px; >.my-td-left< background: white; margin-bottom: 30px; width: 50%; height: auto; vertical-align: top; text-align: left; >.my-td-right < background: transparent; margin-bottom: 30px; width: 50%; height: 50px; vertical-align: top; text-align: left; >tr:nth-child(2n) td

You can use CSS’ nth-child(even) to select every 2nd tr .

Updated Fiddle : https://jsfiddle.net/w5aLf2vc/4/

HTML Table Padding & Spacing, To add padding only above the content, use the padding-top property. And the others sides with the padding-bottom, padding-left, and padding-right properties: Example. th, td < padding-top: 10px; padding-bottom: 20px; padding-left: 30px; padding-right: 40px;>Try it Yourself » HTML Table — Cell Spacing. Cell spacing is …

Good way to add some space between html table rows using css? Works across all browsers including IE6

It’s unfortunately not that intuitive but it works on IE6 and all the other browsers. You can also do it with a border:

To exclude an inner table you could use:

border-spacing is the right way to go, but doesn’t fulfill all your requirements.

Still, you could use it in combination with a little browser-detection: if IE < 8, use a little javascript to add some cellspacing.

Add following rule to tr and it should work

Sample (Open it in IE9 offcourse 🙂 ): http://jsfiddle.net/zshmN/

Css — Spacing between 2 Rows in a HTML table, Spacing between 2 Rows in a HTML table. Ask Question Asked 4 years, 7 months ago. Yes Sir I have used CSS before but unfortunately where I work we are not allowed to make changes or add another CSS File to the Site so I have to work with the raw solution such as Style Tags – Ahmad. Nov 23, 2017 at 18:26. Add a …

How to add space between table rows+ tailwind?

First you need to split the borders with Tailwind border-separate property on the table tag, then add border-spacing-y-3 where: y is the axis and number is the height between row.

Utilities for controlling the spacing between table borders. Tailwind documentation

Use border-seperate and border-spacing-y-4 to add vertical magin only.

 
Chapter Number Chapter Name Added at Status > > > >

How to increase the distance between table columns in, The main problem with using border-spacing is that even the first column would have a spacing in the front. For example, table < border-collapse: separate; border-spacing: 80px 0; >td < padding: 10px 0; >

Источник

Читайте также:  Проверьте является ли двумерный массив симметричным относительно главной диагонали питон
Оцените статью