Spacing among the cells within a table

Is there a method to add some spacing between cells in a table?

I have a custom table implemented using the following structure:

<div class="table">
    <div class="tr">
        <div class="td">asdf</div>
        <div class="td">asdf</div>
        <div class="td">asdf</div>
    </div>
</div>

Here is the CSS:

.table {
    display: table;
    width: 100%;
}
.tr { 
    display: table-row; 
}
.td { 
    display: table-cell;
}

Although this is not the exact code I am using, my implementation follows a similar structure. I have managed to create a visual representation like this:

Example Image

Currently, there is spacing between the cells achieved by applying the following styles to the table div:

border-collapse:separate;
border-spacing: 5px;

However, this spacing extends to the very edges. I am looking to add spacing only between cell 1-2 and cell 2-3, without affecting the other borders. How can I achieve this without overlapping the existing borders?

Answer №1

Opting for negative margin in conjunction with position:relative proved to be a successful alternative to using border-spacing: 5px;.

body{
  background: #ccc;
}
div{
   -webkit-box-sizing: border-box;
   -moz-box-sizing: border-box;
   box-sizing: border-box;
}
.table {
display: table;
width: 100%;
  padding: 0 5px;
}
.tr { 
display: table-row; 
}
.td { 
 background: #fff;
display: table-cell;
  position: relative;
  width: 33.333%;
}
.td:first-child{
  left: -5px;
}
.td:last-child{
  right: -5px;
}
<div class="table">
<div class="tr">
    <div class="td">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda doloribus omnis aliquid ea cumque est ipsam praesentium ratione consectetur quis fuga illo cupiditate error, perferendis, veritatis quae soluta suscipit a?</div>
    <div class="td">asdf</div>
    <div class="td">asdf</div>
</div>
</div>

https://jsfiddle.net/nk4xLdgn/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Angular ngx-color Color Picker is missing the option to customize the width of the color picker

I am currently utilizing the ngx-color Color Picker: https://www.npmjs.com/package/ngx-color#material This is the section where I am implementing the Color Picker and trying to specify the width <div> <div class="flex-title"> ...

Directives for conditions if Internet Explorer is greater than or equal to 9, or if it is not

Embarking on a new project, I find myself in the unfortunate position of having to support IE7 & IE9. However, my goal is to eventually phase out IE7 support smoothly. Ideally, I aim to utilize the latest versions of libraries wherever possible. < ...

Activating the Speech Recognition feature in a form triggers the submission of a post

Currently, I am integrating webkitspeechRecongition into a form to allow users to enter data using their voice by pressing a button. However, a challenge arises when the call is triggered by a button within the form as it results in a post/submit action th ...

Upon reloading, the dynamically generated table does not appear accurately

When a table is dynamically created using JavaScript/jQuery/html from an Ajax call, it initially displays correctly formatted. However, upon refresh/reload, the formatting of the table becomes incorrect. To address this issue, I have implemented a Promise ...

Picking specific <button> items

Presented here are a series of buttons to choose from: <button id="hdfs-test" type="button" class="btn btn-default btn-lg">HDFS</button> <button id="hive-test" type="button" class="btn btn-default btn-lg">HIVE</button> <button id ...

PHP not displaying radio button values

My latest project involved creating a quiz program using only PHP. The program consists of 4 different questions and radio buttons, and when an option is selected, the value of the radio button (A, B, C, or D) should be printed. I have set up 4 PHP varia ...

The peculiar effect of a CSS element's border on surrounding elements is quite unusual

I'm experiencing a strange issue that I can't quite figure out. To demonstrate the problem, I've created a fiddle. What's puzzling me is why applying a border to one of the three canvases causes my other two .headerMainDiv elements to ...

Navigate to the top of the page using jQuery

Attempting to implement a simple "scroll jump to target" functionality. I've managed to set it up for all parts except the "scroll to top". The jumping works based on the tag's id, so it navigates well everywhere else, but not to the very top. He ...

Inheriting the viewBox attribute with SvgIcon

I have a collection of unique custom SVGs, each with its own distinct viewBox. First Custom SVG <svg viewBox="-4 -4 24 24"><path something/></svg> Second Custom SVG <svg viewBox="-5 -7 24 24"><path something ...

I'm encountering an issue with the "z-index: -1" property in React

After creating a form placed alongside buttons, I encountered an issue where the form overlaps the buttons and prevents them from being clicked. Despite setting the z-index to -1, it seems that the form remains clickable even when not visible. Research ind ...

Animation not fluid with ReactCSSTransitionGroup

Currently, I am in the process of developing an image carousel that showcases images moving smoothly from right to left. However, despite its functionality, there seems to be a slight jaggedness in the animation that I can't seem to resolve. Interesti ...

Seeking assistance with creating an iPad application utilizing JQtouch - any t

I am attempting to create an iPad app using jQuery and jQTouch for the second time. I want to split the existing jQTouch theme designed for iPhone, which uses one window, into two separate windows optimized for the iPad. My goal is to have navigation on t ...

What advantages and disadvantages come with the top Java HTML parsing tools on the market?

In my search on StackOverflow and Google, I have come across a few recommended Java HTML parsers that different parties consistently suggest. However, I've had trouble finding in-depth information on the strengths and weaknesses of these libraries. I& ...

"Restricting the height of a DIV container based on the size

Struggling with CSS as I try to get my #wrapper DIV to adjust its size based on its contents. I've experimented with 100% height and min-height, but nothing seems to work. Could it be related to relative versus absolute positioning? Here's a snip ...

Updating the text input value in a database with PHP upon button click

Here is a breakdown of what has been implemented so far: The database table is named adhar_card. Below is the structure image for reference (Adhard_card_id serves as the primary key). https://i.sstatic.net/8j4m6.jpg Clicking on the verify button will cha ...

Alter the color scheme using jQuery

Exploring the world of websites, I've come across many with a unique color switch feature. Users have the ability to choose a color, and the entire page transforms to match their selection. Check out these links for some examples... http://csmthe ...

extracting the HTML content from JavaScript and saving it into a standalone file

update When I click a link, a popup opens and I see all this HTML. The smile method is called when I click the link, and we append HTML in that method so that we can see it when the popup is opened. I moved it to a separate file something.component.html, ...

Decide on the chosen option within the select tag

Is there a way to pre-select an option in a combobox and have the ability to change the selection using TypeScript? I only have two options: "yes" or "no", and I would like to determine which one is selected by default. EDIT : This combobox is for allow ...

The simplest way to increase the size of a child element in order to generate a scrollable area

When working with HTML, it's important to consider how the size of a child div affects the parent div. If the child div is larger than its parent, scrollbars will appear on the parent div if the appropriate style rules are set. However, I'm inte ...

"Subtle Website Background Fade Effect When Menu is Hovered Over

Click on the following link to observe a transition effect that occurs on the body of the website when interacting with the main menu system: Here is the website Do you know what this effect is called and how it can be integrated into a website? ...