{"id":1481,"date":"2017-03-21T17:48:11","date_gmt":"2017-03-21T12:18:11","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=1481"},"modified":"2017-03-29T10:53:51","modified_gmt":"2017-03-29T05:23:51","slug":"space-between-two-rows-in-a-table","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/space-between-two-rows-in-a-table\/","title":{"rendered":"[Solved &#8211; 11 Answers] CSS &#8211; HTML &#8211; Space between two rows in a table"},"content":{"rendered":"<p><label class=\"label label-Warning\">PROBLEM :<\/label><\/p>\n<p>Is this possible via CSS?<\/p>\n<p><strong>We are trying<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">tr.classname {<br\/>  border-spacing: 5em;<br\/>}<\/code><\/pre> <\/div>\n<p>to no avail.<\/p>\n<p><label class=\"label label-info\">SOLUTION 1<\/label><\/p>\n<ul>\n<li>You need to use padding on your td elements.<\/li>\n<li>Something like this should do the trick. You can, of course, get the same result using a top padding instead of a bottom padding.<\/li>\n<li>In the CSS code below, the greater-than sign means that the padding is only applied to td elements that are direct children to tr elements with the class spaceUnder.<\/li>\n<li>This will make it possible to use nested tables. (Cell C and D in the example code.) it shouldn&#8217;t break the code in any modern browsers.<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">\/* Apply padding to td elements that are direct children of the tr elements with class spaceUnder. *\/<br\/>tr.spaceUnder &gt; td<br\/>{<br\/>  padding-bottom: 1em;<br\/>}<\/code><\/pre> <\/div>\n<p><strong>HTML code:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Html Code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;table&gt;<br\/>  \t\t&lt;tbody&gt;    &lt;tr&gt;<br\/>      \t\t&lt;td&gt;A&lt;\/td&gt;<br\/>      \t\t&lt;td&gt;B&lt;\/td&gt;    &lt;\/tr&gt;<br\/>    \t\t&lt;tr class=&quot;spaceUnder&quot;&gt;<br\/>      \t\t&lt;td&gt;C&lt;\/td&gt;<br\/>      \t\t&lt;td&gt;D&lt;\/td&gt;    &lt;\/tr&gt;<br\/>    \t\t&lt;tr&gt;<br\/>      \t\t&lt;td&gt;E&lt;\/td&gt;<br\/>      \t\t&lt;td&gt;F&lt;\/td&gt;    &lt;\/tr&gt;  &lt;\/tbody&gt;&lt;\/table&gt;<\/code><\/pre> <\/div>\n<p><strong>This should render somewhat like this:<\/strong><\/p>\n<p>+&#8212;+&#8212;+<\/p>\n<p>| A | B |<\/p>\n<p>+&#8212;+&#8212;+<\/p>\n<p>| C | D |<\/p>\n<p>|\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0 |<\/p>\n<p>+&#8212;+&#8212;+<\/p>\n<p>| E | F |<\/p>\n<p>+&#8212;+&#8212;+<\/p>\n<p><label class=\"label label-info\">SOLUTION 2<\/label><\/p>\n<p>In the parent table, try setting<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">border-collapse:separate; <br\/>border-spacing:5em;<\/code><\/pre> <\/div>\n<p>Plus a border declaration, and see if this achieves your desired effect. Beware, though, that IE doesn&#8217;t support the &#8220;separated borders&#8221; model.<\/p>\n<p><label class=\"label label-info\">SOLUTION 3<\/label><\/p>\n<p>You have table with id albums with any data,omitted the trs and tds<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Html Code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;table id=&quot;albums&quot; cellspacing=&quot;0&quot;&gt;       <br\/>&lt;\/table&gt;<\/code><\/pre> <\/div>\n<p><strong>In the css:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">table#albums <br\/>{<br\/>    border-collapse:separate;<br\/>    border-spacing:0 5px;<br\/>}<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<p><label class=\"label label-info\">SOLUTION 4<\/label><\/p>\n<p>since we have a background image behind the table, faking it with white padding wouldn&#8217;t work.<\/p>\n<p><strong> we opted to put an empty row in-between each row of content:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Html Code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;tr class=&quot;spacer&quot;&gt;&lt;td&gt;&lt;\/td&gt;&lt;\/tr&gt;<\/code><\/pre> <\/div>\n<p>Then use css to give the spacer rows a certain height and transparent background.<\/p>\n<p><label class=\"label label-info\">SOLUTION 5<\/label><\/p>\n<p><strong>You may try to add separator row:<\/strong><\/p>\n<p><strong>Html:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Html Code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;tr class=&quot;separator&quot; \/&gt;<\/code><\/pre> <\/div>\n<p><strong>css:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">table tr.separator { height: 10px; }<\/code><\/pre> <\/div>\n<p><label class=\"label label-info\">SOLUTION 6<\/label><\/p>\n<p><strong>you can do<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">tr.classname td <br\/>{<br\/>background-color:red; <br\/>border-bottom: 5em solid white<br\/>}<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<p>Make sure the background color is set on the td rather than the row. This should work across most browsers&#8230;<\/p>\n<p><label class=\"label label-info\">SOLUTION 7<\/label><\/p>\n<p><strong>You can use line-height in the table:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Html Code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;table style=&quot;width: 400px; line-height:50px;&quot;&gt;<\/code><\/pre> <\/div>\n<p><label class=\"label label-info\">SOLUTION 8<\/label><\/p>\n<p>You need to set border-collapse: separate; on the table; most browser default stylesheets start at border-collapse: collapse;, which ditches border spacing.<\/p>\n<p>Also, border-spacing: goes on the TD, not the TR.<\/p>\n<p><strong>Try:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Html Code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;html&gt;&lt;head&gt;&lt;style type=&quot;text\/css&quot;&gt;<br\/>    \t#ex    { border-collapse: separate; }<br\/>    \t#ex td { border-spacing: 1em; }<br\/>\t&lt;\/style&gt;&lt;\/head&gt;&lt;body&gt;<br\/>    \t &lt;table id=&quot;ex&quot;&gt;<br\/>\t&lt;tr&gt;&lt;td&gt;A&lt;\/td&gt;<br\/>\t&lt;td&gt;B&lt;\/td&gt;&lt;\/tr&gt;<br\/>\t&lt;tr&gt;&lt;td&gt;C&lt;\/td&gt;<br\/>\t&lt;td&gt;D&lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;<br\/>\t&lt;\/body&gt;<\/code><\/pre> <\/div>\n<p><label class=\"label label-info\">SOLUTION 9<\/label><\/p>\n<p>If you apply float to tr elements, you can space between two rows with margin attribute.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">table tr{<br\/>\t\tfloat: left<br\/>\t\twidth: 100%;<br\/>\t\t}<br\/><br\/>\t\ttr.classname {<br\/>\t\tmargin-bottom:5px;<br\/>\t\t}<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<p><label class=\"label label-info\">SOLUTION 10<\/label><\/p>\n<p>For creating an illusion of spacing between rows, apply background color to row and then create a thick border with white color so that a &#8220;space&#8221; is created .<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">tr <br\/>\t\t{<br\/>   \t                      background-color: #FFD700;<br\/>  \t                      border: 10px solid white;<br\/>\t\t}<\/code><\/pre> <\/div>\n<p><label class=\"label label-info\">SOLUTION 11<\/label><\/p>\n<p><strong>Simply put div inside the td and set the following styles of div:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Css Code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">margin-bottom: 20px;<br\/>\t\theight: 40px;<br\/>\t\tfloat: left;<br\/>\t\twidth: 100%;<\/code><\/pre> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>PROBLEM : Is this possible via CSS? We are trying to no avail. SOLUTION 1 You need to use padding on your td elements. Something like this should do the trick. You can, of course, get the same result using a top padding instead of a bottom padding. In the CSS code below, the greater-than [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,24],"tags":[2958,2967,2959,2956,2963,2966,2955,2969,2957,2968,2964,2962,2970,2960,2965,2961],"class_list":["post-1481","post","type-post","status-publish","format-standard","hentry","category-css","category-html","tag-css-border-spacing-property","tag-display-table-row-padding","tag-how-to-add-space-between-table-rows","tag-how-to-break-a-line-or-space-in-between-two-rows-of-the-html-table","tag-how-to-give-space-between-two-rows-in-html","tag-how-to-give-space-between-two-tables-in-html","tag-html-css-how-do-i-create-a-gap-between-rows-in-a-table","tag-html-row-padding","tag-html-table-cellspacing-attribute","tag-html-table-remove-space-between-rows","tag-html-table-spacing-between-columns","tag-row-spacing-in-tables","tag-space-between-rows-bootstrap","tag-spacing-how-to-set-the-space-between-rows-in-a-table","tag-table-border-spacing","tag-what-is-the-syntax-for-having-a-break-between-two-rows"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=1481"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1481\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=1481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=1481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=1481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}