Double border coming in every row of table - css

There is a table which I have given border. After giving border there were double border that were coming after some googling I found that border-collapse is my saviour. but after trying to use it in every possible way it is not working.
There is a double border at the bottom that is coming that I want to remove.
For better understanding attached screen shot:
I want to remove the double border coming after each cell.
Markup.
<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse;">
<thead>
<tr>
<th >
Login Name
</th>
<th>
SheetName
</th>
</tr>
</thead>
<tr>
<td>aaa</td>
<td>abc</td>
</tr>
<tr>
<td>asdfasdf</td>
<td>aasdfsadfbc</td>
</tr>
</table>

CSS is needed to provide a definite answer. As others said, make sure there aren't any global CSS files altering your HTML. It appears your CSS has a tr {margin-top:10px;} set in it, or something providing a similar effect.
Just out of curiosity, why are you using the HTML cellpadding attribute? The CSS padding attribute can perform the same function and provides much more flexibility. You will also find separating your styles (CSS) from your HTML will make changing and updating much easier than going back to modify each inline style.
<table id="table">
<thead>
<tr>
<th >
Login Name
</th>
<th>
SheetName
</th>
</tr>
</thead>
<tr><td>aaa</td><td>abc</td></tr>
<tr><td>asdfasdf</td><td>aasdfsadfbc</td></tr>
</table>
CSS:
#table {
padding: 10px 5px 10px 5px;
//this is shortand for top right bottom left
border-collapse: collapse;
//this is becoming deprecated and is mainly used to support older versions of IE
}

Related

background-image CSS property doesn't display on narrow rows

I've isolated a problem in my project down to this: Using a small background image, the image isn't displayed in smaller cells of a table when set to display on the entire row. Setting the width >5% suddenly fixes this issue, and I'd like to know why.
I'm using bootstrap 4 with a custom class I've written. Here's a fiddle with all the unnecessary parts of my project removed: https://jsfiddle.net/5y4gs8co/11/ Notice that cells 5.x do not display the background.
I've tested a few images, and this only happens with certain image sizes. This is where I'm stuck -- I don't want to use an unnecessarily large image here and I think there may be a solution.
.progress-bg {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAACCAIAAADuA9qHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFwmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJ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MTAtMWM4Nzk1MjUxZjY4IiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9InhtcC5kaWQ6YTBmMGY4MDQtOGRmMC0yMTQ1LWI5ZjYtZGEyNzkxNDAyM2MwIiBkYzpmb3JtYXQ9ImltYWdlL3BuZyIgcGhvdG9zaG9wOkNvbG9yTW9kZT0iMyI+IDx4bXBNTTpIaXN0b3J5PiA8cmRmOlNlcT4gPHJkZjpsaSBzdEV2dDphY3Rpb249ImNyZWF0ZWQiIHN0RXZ0Omluc3RhbmNlSUQ9InhtcC5paWQ6YTBmMGY4MDQtOGRmMC0yMTQ1LWI5ZjYtZGEyNzkxNDAyM2MwIiBzdEV2dDp3aGVuPSIyMDE5LTA2LTE5VDA5OjI5OjA5LTA0OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ0MgKFdpbmRvd3MpIi8+IDxyZGY6bGkgc3RFdnQ6YWN0aW9uPSJzYXZlZCIgc3RFdnQ6aW5zdGFuY2VJRD0ieG1wLmlpZDpiZWQwZjg4MS1kMjllLWMzNDYtODk5Yy1iMjViNDIwMjVkMGUiIHN0RXZ0OndoZW49IjIwMTktMDYtMTlUMDk6Mjk6MDktMDQ6MDAiIHN0RXZ0OnNvZnR3YXJlQWdlbnQ9IkFkb2JlIFBob3Rvc2hvcCBDQyAoV2luZG93cykiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPC9yZGY6U2VxPiA8L3htcE1NOkhpc3Rvcnk+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+MDui9AAAABVJREFUCJljfPv/NQNuwIRHjoGBAQCrIALb0W2etgAAAABJRU5ErkJggg==') !important;
background-size: /*var(--percent)*/
100% 100%;
background-repeat: no-repeat;
}
Update: Reported the bug to the chrome bug tracker. Another workaround is adding a border: solid; to the <tr> element
Seems like another strange behaviour or tables when width is assigned in %. And this is independent of bootstrap.
I have no clue to why this happens but yes, there are a few strange behaviours of <table> when width of <td> is assigned in %. This i guess is one of them.
Maybe <table> were never designed to handle % value.
But as a solution to your problem, you can either replace width:5% to width: {required}px, or you can change below style rules of the .progress-bg css class:
.progress-bg {
background-image: url({requiredUrl});
background-repeat: repeat;
}
Consider adding the background on th and td tag.
.progress-bg th, .progress-bg td {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAACCAIAAADuA9qHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFwmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDIgNzkuMTYwOTI0LCAyMDE3LzA3LzEzLTAxOjA2OjM5ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdEV2dD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlRXZlbnQjIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ0MgKFdpbmRvd3MpIiB4bXA6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BDQyAoV2luZG93cykiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPC9yZGY6U2VxPiA8L3htcE1NOkhpc3Rvcnk+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+MDui9AAAABVJREFUCJljfPv/NQNuwIRHjoGBAQCrIALb0W2etgAAAABJRU5ErkJggg==') !important;
background-size: 100% 100%;
background-repeat: no-repeat;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Description</th>
<th scope="col" style="width:5%">5%</th>
<th scope="col" style="width:6%">6%</th>
</tr>
</thead>
<!-- Table Body -->
<tbody>
<tr class="progress-bg">
<th scope="row">
First Item, With A Longer Title
</th>
<td>
A longer description, neat!
</td>
<td>
5.1
</td>
<td>
6.1
</td>
</tr>
<tr class="progress-bg">
<th scope="row">
Second Item, With A Longer Title
</th>
<td>
A longer description, neat!
</td>
<td>
5.2
</td>
<td>
6.2
</td>
</tr>
<tr class="progress-bg">
<th scope="row">
Third Item, With A Longer Title
</th>
<td>
A longer description, neat!
</td>
<td>
5.3
</td>
<td>
6.3
</td>
</tr>
</tbody>
</table>
</div>
#sudipto-roy Gave some good insight, and after a bit more testing this only happens in Chrome 75, IE 11, and Edge 18. FF 67 and Opera 60 render it properly. My solution was to raise the image dimensions, being mindful of what would compress well to base64. In my case the image was doubled in dimensions but only cost an additional ~20 Bytes.
I wish I could give more insight into what exact conditions cause this, but making the image larger seems to be a decent workaround.

CSS - Hide td in body if th has class

I need to hide td in the body if the th in the head has the class .isSystem
Is this possible in straight CSS?
More info: the table is built dynamically. The head/columns is an array... and the tbody/rows is another array. I'm using Angular/typescript...
I tried this: th.isSystem ~ td { text-decoration: line-through; color: red; }
If the table is built dynamically, then the obvious way is to use col rather than th to drive this behaviour. <col> elements have special powers which enable them to affect the cells they belong to.
table {border:1px outset;}
th, td {border:1px inset;}
col.isSystem {visibility:collapse;}
<table>
<col/><col class="isSystem"/><col/><col/>
<thead>
<tr><th>One</th> <th>Two</th> <th>Three</th> <th>Four</th></tr>
</thead>
<tbody>
<tr><td>This</td> <td>This</td> <td>This</td> <td>This</td></tr>
<tr><td>is</td> <td>is</td> <td>is</td> <td>is</td></tr>
<tr><td>the</td> <td>the</td> <td>the</td> <td>the</td></tr>
<tr><td>first</td> <td>second</td><td>third</td> <td>fourth</td></tr>
<tr><td>column</td><td>column</td><td>column</td><td>column</td></tr>
</tbody>
</table>
Disclaimer: this works as advertised in Firefox, IE11 and Edge. Chrome however... sorry.
Bottom Line:
No, because <td> and <th> can not be siblings since they are not proper children of a <table> and even if your source markup has them that way - the browser will adjust the markup and overrule your styles.
Long explanation:
Looking at a more JS related SO question on the subject, the browser automatically will inject <thead> and <tbody> around your <th> and <tr> (subsequently <td>) elements. <thead> and <tbody> are valid child elements of <table> - <th> and <tr> are not.
As a result, finding the siblings of <th> will only return other th tags, since they technically live in a <thead> - the <td> are in a <tr> in <tbody>
Take a look at these examples:
Example 1
Codepen with straight <th> and <tr> elements
.isSystem + .row { background:red }
<table>
<th class="isSystem">Table Heading</th>
<tr class="row">
<td>Table Item</td>
</tr>
</table>
<div class="isSystem">Div Heading</div>
<div class="row">Div Item</div>
In this example, you would expect the table row to be red... The div elements in the example do this but the <tr> doesn't
Example 2
Codepen with proper <thead> and <tbody> elements
In example 2, wrapping the table with the correct thead and tbody elements, you can acheive this:
.isSystem + .rows tr { background:red; }
<table>
<thead class="isSystem"><th>Heading</th></thead>
<tbody class="rows">
<tr class="row"><td>Item</td></tr>
</tbody>
</table>
Unfortunately if your items are dynamically generated and you can not apply your classes in this way, then your only option will be using JS to target your elements as others have already mentioned. However, I would do what's possible to create proper semantic markup first.

How can I fix the header of a table whose width is not fixed?

I have a table to which a user can add new columns. The width hence is not fixed. How can I fix the header for such a table?
I tried:
display:block
overflow-x:hidden
overflow-y:auto
height:70%
in table body. It worked partially.
If I understand your question correctly (posting your HTML would help) you can nest a table inside the part that can be extended. You will be able to add as many columns (<td>) without effecting the table header.
table td table td {
border: solid 1px grey;
}
<table>
<tr>
<th>Add your fixed table header</th>
</tr>
<tr>
<td>
<table>
<tr>
<td>New Columns</td>
<td>can be added</td>
<td>without effecting your header</td>
</tr>
</table>
</td>
</tr>
</table>

Bootstrap 3 tables column width control

I have a bootstrap table as follows:
<table class="table table-bordered">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
</tr>
</thead>
<tbody>
<tr>
<td>test</td>
<td>test</td>
</tr>
</tbody>
</table>
The two column are equally spaced which is fine but if i drop an <input> element in to one of the columns this column stretches to take up about 3/4 of the overall table.
http://www.bootply.com/115049
My question is why does it do this and how can I control it?
Any help much appreciated.
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-10">Col1</th>
<th class="col-md-2">Col2</th>
</tr>
</thead>
<tbody>
<tr>
<td>test</td>
<td>test</td>
</tr>
</tbody>
</table>
This is down to the way HTML tables work. By default, table cells will scale according to their contents - any size you give them is used as a guide. So, for instance:
td {
width: 50%;
/*
If this cell is empty, it will take up half of
the table. But if the content needs to, it will
expand to take up more space.
*/
}
You can work around this by setting table-layout: fixed; in your CSS:, e.g.
table.fixed {
table-layout: fixed;
}
This makes tables adhere more strictly to the dimensions you set in CSS, rather than what the content dictates. See https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout for more information.
Once this is done, you can apply the normal Bootstrap grid classes to control the width. Apply them to the cells (td or th) in the first row and they'll repeat all the way down.
Why ? I don't know :)
How to control it ?
You can simply but a width parameter to your td, such as :
<td width=50%><input type="text"></td>
You can do it like this, or using your css file by saying all from this class should take half of the table width.
td {
width: 50%;
}

td with colspan border broken in ie10 quirk mode

ie10 is not showing fine border over colspan.
It is showing well on other browser, but not on IE 10.
I'll post my code below.
HTML CODE:
<table>
<thead>
<tr>
<td rowspan="2">1</td>
<td rowspan="2">2</td>
<td colspan="4">3</td>
<td rowspan="2">4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td colspan="2">7</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td colspan="3">4</td>
<td>5</td>
</tr>
</tbody>
</table>
CSS CODE:
table tr td {
border: 1px solid black;
width: 100px;
}
table {
border-collapse:collapse;
}
border under 7 is gone. How can I show it?
here is example on jsfiddle :
http://jsfiddle.net/H4z7Q/
ADD: If some event occurs in ie10, border come back to normal.
You can use table inline style stats. instead of border-collapse:collapse;
<table cellpadding=0 cellspacing=0>
will count as same effect.
but will return and will chrice ur problem
The markup violates the HTML table model, as you can see by checking it with http://validator.w3.org which says, referring to the first row: “Table column 6 established by element td has no cells beginning in it”.
So all bets are off. Modify the table structure so that it conforms, or try to achieve the desired layout using other tools than a layout table.

Resources