border-right don't work in Firefox browser - css

#content table.datatable th {
border:1px solid #000;
border-right:1px solid black;
border-color:black;
}
border-right dont work for th-table header elements in Firefox browser. Any suggestions please.

the css is working just fine. You might want to change the colors, just to be able to see the changes
#content table.datatable th {
border:1px solid #000;
border-right:1px solid red;
/*border-color:black;*/
}
If you still do not see any change, you might be having wrong markup. It should look something like this:
<div id="content">
<table class="datatable">
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
</div>
Note: The contents of div, table, th, td are dummy and nothing else.

In the code snippet you give you've set the border colour to be black 3 times over. If in your live code you have a different colour (say blue, for example) in the second line, then your first statement will set the colour for the whole border to be black (#000), then the second one will set the right border only to be blue. So far so good. But then your third line border-color:black sets the whole border to be black again, thus overriding the second line.
If you have two conflicting property settings like this in the same CSS rule, then the later one will overrule the earlier one. (This is just the same as the more usual situation where a rule later in the stylesheet will override one earlier in that stylesheet, or in an earlier stylesheet, given two rules with the same specificity.)
Putting it another way, the fact that one setting is for border and another is for border-right doesn't change anything; the border property is just a composite way of setting the four properties of the left, right, top and bottom borders all in one go. It's the order these settings appear in that matters, not whether you are specifying the four-in-one border or a single side only.

Related

tbody border is rendering issue

I'm using angularJS to ngRepeat over a number of search results in order to display them in a table. Each result consists of a number of table rows and columns, so the ngRepeat is repeating a tbody container to encompass a full result.
The issue I'm having is in styling a border around each tbody. Each border is to transition from transparent to a specified color on mouseover, however the edges of the borders appear overlapped due to the default border-collapse: collapse; property, which makes them appear cut-off, and generally broken. I can make the border appear correct if I use border-collapse: separate; and display: block;, but I lose the nice horizontal spacing of columns that the table would normally provide.
My goal is for each tbody to have it's own border so I can transition the color on mouseover, while maintaining proper horizontal spacing with respect to the th tags that are displayed at the top of the table.
Here is a simplified version of what I have:
HTML:
<table>
<thead>
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
</thead>
<tbody ng-repeat="result in results">
<tr>
<td>{{result.a}}</td>
<td>{{result.b}}</td>
<td>{{result.c}}</td>
</tr>
<tr>
<td colspan="3">
<div>{{result.d}}</div>
</td>
</tr>
</tbody>
CSS:
tbody {
transition: border-color 0.6s ease;
-webkit-transition: border-color 0.6s ease; /* Safari */
border 4px solid black;
}
tbody:hover {
border-color: red;
}
I've consulted:
tbody border not showing,
Add borders on <tbody>,
Border-top from tbody and border-bottom from thead don't work at the same time?
amongst others..
Thanks in advance.
Just for anyone who runs into a similar issue in the future, I ended up solving this problem by avoiding using a table and the tbody tag entirely. I setup the layout to visually resemble a table using a series of divs, allowing me to apply the border to a div in the usual way. The down side to this approach is that you lose the automatic column width sizing based on the contained content, but the upside is that you avoid the border issues described above.
I hope that helps.

:before pseudo-element causes gap in border

I have this piece of HTML that I want to style.
The html is a table (and actual table), which I want to give a border.
The element also had a :before pseudo-element, which I use to put a small triangle in the top corner.
The JSFiddle is here.
I hope it makes sense. I stripped down the markup and the CSS as much as possible, because it's actually a small part of a big site.
http://jsfiddle.net/GolezTrol/28yDb/2/
Now the problem is that the combination of having 2 columns, having border-collapse: collapse; on the table and the :before pseudo element, cause the top border of the element to partially disappear. It's only there for the length of the first column.
You would assume that it is the pseudo element that is on top of the border, but this element is very small, and as far as I can tell, this could not be the problem. I added visibility: hidden; to the pseudo element to be sure, and I can tell that the triangle is gone, but the border is still incomplete.
Unfortunately I cannot change the markup, since this is outputted by MediaWiki, but I do have full control over the CSS.
The HTML:
<div id="globalWrapper">
<div id="column-content">
<div class="thumb tright">
<table class="infobox vcard" style="">
<tbody>
<tr>
<th colspan="2" class="fn org" style=""> Example text</th>
</tr>
<tr>
<th>Row head</th>
<td>Content</td>
</tr>
The CSS:
/* Generic table styling */
table {
border-collapse: collapse;
/*border-spacing: 0;*/ }
/* The box */
.thumb.tright table.infobox.vcard {
border: 3px solid #fae104;
position: relative;
}
/* Triangle */
.thumb.tright table.infobox.vcard:before {
content: "";
position: absolute;
width: 0;
height: 1px;
border-top: 5px solid transparent;
top: -7px;
border-left: 10px solid #555;
visibility: hidden;
right: -1px; }
I already found out that it works when I remove border-collapse: collapse;, but I'm not sure that is a proper solution, and even if it is, I would really like an explanation of what is going on.
Btw. I got this problem both in Chrome 29 and in Internet Explorer 10. Haven't tested other browsers.
Update
Instead of using -or not using- 'border-collapse' to fix the problem, I found out that this also works:
.thumb.tright table.infobox.vcard tbody {
display: block;
}
So the table itself is still a table, the pseudo element is still on the table, as is the border, positioning etc. The tbody, which was unstyled before, is now a block and the problem is solved in both browsers. I found this by trial and error, and still wouldn't know the reason behind it.
Updated fiddle: http://jsfiddle.net/GolezTrol/28yDb/9/
Being a newbie to StackOverflow and jsFiddle I updated the Fiddle with that I think is the solution. I didn't change the CSS except for moving the pseudo class from the table itself to the table header, and changing it into :after. Works for me in Firefox and Chrome!
/* Triangle */
.thumb.tright table.infobox.vcard th:after { }
Border-collapse: seperate is not supported in IE8 but I think this will be.
edit: nevermind ;)
It is a problem only occur on Webkit browsers I think. It can be considered a "browser bug" imo.
th should be inside thead, not tbody:
<thead>
<tr>
<th colspan="2" class="fn org" style=""> Example text</th>
</tr>
</thead>
<tbody>
<tr>
<th>Row head</th>
<td>Content</td>
</tr>
<tbody>
And I think this is the correct solution. You are putting an element where it is not advised to be, so it should be normal for a problem to occur.
Edit: as thirtydot pointed out, changing the th to td doesn't change the result. It only work when I moved the th to the thead section. At this point I am at a loss, I can't find a way to solve this.
But at least I think I can provide my speculation on the cause of this problem:
:before create a pseudo element inside the target element. What kind of element is unknown to me, but I suspect that the browser create a td. If that is true, then after rendering your html should look like this:
<table>
<td></td> /*the pseudo element*/
<tbody>
<tr>
<th colspan="2" class="fn org" style=""> Example text</th>
</tr>
<tr>
<th>Row head</th>
<td>Content</td>
</tr>
<tbody>
</table>
Needless to say this look weird. And if you try the above html out you can see the result is similar to your problem. border-collapse:collapse will merge 2 borders together where there are 2 cells next to each other, or a cell is next to the table's border. So I suspect in this case, the pseudo element - which doesn't have appropriate colspan - last only 1 column, the rest of that row is empty: nothing's there. This is where I think caused the bug: because there's no cells next to the table border there, no border is created at all.
The real reason may be a little bit more complicated ("why doesn't the bug occur when I put in a thead?"), but I think my answer is not too far off the mark. :)
The only reasonable explanation I can think of is pseudo-element :before not being compatible with the display: table of the table in collapsed mode. That is why border-collapse: separate; solves the problem. Suddenly, the browser can display the top border not caring about the pseudo element.
If you look closely, you can clearly see that the missing part of the border is the width of the second column. If you change it to after pseudo element, the border is missing in the bottom-right corner, again due to the fact that the borders of the table and the pseudo-element are collapsed.
If you change the border-bottom of th to be 3px solid red in collapsed mode, the th overpowers the table and the border is red. I presume, the power of after and before follow the same rule. It would be nice if someone who knows the specs better came to answer that.
Thinking this way, I do not believe there can be any other solution than:
using separate borders
putting the pseudo element on the parent div
What I inspected is that the pseudo element is actually rendered as block and can be change to table and list-item. However, none of these change the behaviour.
Very random stuff that is actually compliant with Av Avt's answer about where the pseudo element is rendered in regards of the DOM.
If I append the :beofre like this, the border stays:
.thumb.tright table.infobox.vcard tr:before
Obviously, it creates as many new pseudo element as there are rows.

CSS - bottom border around a TD gets cut off when browser is resized

I have a web app that uses bootstrap to make it mobile friendly.
In an attempt to visually group 3 items together, I have created a class the puts a box / border around the table cell where these three items appear. (the three items are link4, 5 and 5)
Here's the class:
td.lights
{
border: 2px solid black;
}
And here's the problematic HTML - I've paired it down to the minimum code, just for demo purposes.
What I'm noticing is that when I simulate a mobile device (using Firefox's Responsive design view tool) the bottom of the
<table>
<tbody>
<tr>
<td>link1</td>
<td>link2</td>
<td>link3</td>
<td> </td>
<td class="lights">link4 / link5 / link6</td>
</p>
</tbody>
</table>
Immediately after this table, I have this code to create another table:
<P>
<table class="table table-bordered table-striped">
<thead>
etc...
</thead>
</table>
When i resize my browser, the border on the bottom of my in table 1 gets cut off, depending on how small by browser size gets. The other fields look fine, but then again, they don't have a border around them. To me, it looks like there's a fixed set of space above and below my text ("link4 / link5 / link6") that is not dynamically changing.
I've tried adding a height "dynamic" height property to my td like so:
td.lights
{
border: 2px solid black;
height: 1em;
}
But that didn't resolve my problem.
Any suggestions? Please and thanks!
As far as I can tell you have quite a few errors in your markup:
</p>
Should be:
</tr>
Also, should you have a:
<P>
Before your second table? I would avoid wrapping your tables with P tags as this will add unwanted padding and doesn't make sense from a semantic perspective.
Fix those first and see what happens. Secondly I would recommend - when dealing with tables - to use the following:
<table cellpadding="0" cellspacing="0" border="0">
You can also do this in CSS with the following:
table, tr, td { margin: 0; padding: 0; border: 0; }
This should make sure you have no unwanted padding in and around your cells.

How to add a margin to a table row <tr> [duplicate]

This question already has answers here:
CSS: how do I create a gap between rows in a table?
(12 answers)
Space between two rows in a table?
(30 answers)
Closed 3 years ago.
I have a table containing many rows. Some of these rows are class="highlight" and signify a row that needs to be styled differently and highlighted. What I'm trying to do is add some extra spacing before and after these rows so they appear slightly separated from the other rows.
I thought I could get this done with margin-top:10px;margin-bottom:10px; but it's not working. Anyone knows how to get this done, or if it could be done? Here's the HTML and I've set the 2nd tr in the tbody to class highlight.
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Value1</td>
<td>Value2</td>
</tr>
<tr class="highlight">
<td>Value1</td>
<td>Value2</td>
</tr>
<tr>
<td>Value1</td>
<td>Value2</td>
</tr>
<tr>
<td>Value1</td>
<td>Value2</td>
</tr>
</tbody>
</table>
The border-spacing property will work for this particular case.
table {
border-collapse:separate;
border-spacing: 0 1em;
}
Reference.
Table rows cannot have margin values. Can you increase the padding? That would work. Otherwise you could insert a <tr class="spacer"></tr> before and after the class="highlighted" rows.
You can't style the <tr>s themselves, but you can give the <td>s inside the "highlight" <tr>s a style, like this
tr.highlight td {
padding-top: 10px;
padding-bottom:10px
}
This isn't going to be exactly perfect though I was happy to discover that you can control the horizontal and vertical border-spacing separately:
table
{
border-collapse: separate;
border-spacing: 0 8px;
}
line-height can be the possible solution
tr
{
line-height:30px;
}
I know this is kind of old, but I just got something along the same lines to work. Couldn't you do this?
tr.highlight {
border-top: 10px solid;
border-bottom: 10px solid;
border-color: transparent;
}
Hope this helps.
First of all, don't try to put a margin to a <tr> or a <td> because it won't work in modern rendering.
Solution 1
Although margin doesn't work, padding does work :
td{
padding-bottom: 10px;
padding-top: 10px;
}
Warning : This will also push the border further away from the element, if your border is visible, you might want to use solution 2 instead.
Solution 2
To keep the border close to the element and mimic the margin, put another <tr> between each of your reel table's <tr> like so :
<tr style="height: 20px;"> <!-- Mimic the margin -->
</tr>
A way to mimic the margin on the row would be to use the pseudo selector to add some spacing on the td.
.highlight td::before, .highlight td::after
{
content:"";
height:10px;
display:block;
}
This way anything marked with the highlight class will be separated top and bottom.
https://jsfiddle.net/d0zmsrfs/
Because margin is ignored on tr, I usually use a workaround, by setting a transparent border-bottom or border-top and setting the background-clip property to padding-box so the background-color does not get painted underneath the border.
table {
border-collapse: collapse; /* [1] */
}
th, td {
border-bottom: 5px solid transparent; /* [2] */
background-color: gold; /* [3] */
background-clip: padding-box; /* [4] */
}
Makes sure cells share a common border, but is completely optional. The solution works without it.
The 5px value represents the margin that you want to achieve
Sets the background-color of your row/cell
Makes sure the background get not painted underneath the border
see a demo here: http://codepen.io/meodai/pen/MJMVNR?editors=1100
background-clip is supported in all modern browser. (And IE9+)
Alternatively you could use a border-spacing. But this will not work with border-collapse set to collapse.
You might try to use CSS transforms for indenting a whole tr:
tr.indent {
-webkit-transform: translate(20px,0);
-moz-transform: translate(20px,0);
}
I think this is a valid solution. Seems to work fine in Firefox 16, Chrome 23 and Safari 6 on my OSX.
Here's a neat way I did it:
table tr {
border-bottom: 4px solid;
}
That will add 4px of vertical spacing between each row. And if you wanted to not get that border on the last child:
table tr:last-child {
border-bottom: 0;
}
Reminder that CSS3 pseudo-selectors will only work in IE 8 and below with selectivizr.
I gave up and inserted a simple jQuery code as below. This will add a tr after every tr, if you have so many trs like me.
Demo: https://jsfiddle.net/acf9sph6/
<table>
<tbody>
<tr class="my-tr">
<td>one line</td>
</tr>
<tr class="my-tr">
<td>one line</td>
</tr>
<tr class="my-tr">
<td>one line</td>
</tr>
</tbody>
</table>
<script>
$(function () {
$("tr.my-tr").after('<tr class="tr-spacer"/>');
});
</script>
<style>
.tr-spacer
{
height: 20px;
}
</style>
A hack to give the appearance of margins between table rows is to give them a border the same color as the background. This is useful when styling a 3rd party theme where you can't change the html markup. Eg:
tr{
border: 5px solid white;
}
add a div to the cells that you would like to add some extra spacing:
<tr class="highlight">
<td><div>Value1</div></td>
<td><div>Value2</div></td>
</tr>
tr.highlight td div {
margin-top: 10px;
}
You can create space between table rows by adding an empty row of cells like this...
<tr><td></td><td></td></tr>
CSS can then be used to target the empty cells like this…
table :empty{border:none; height:10px;}
NB: This technique is only good if none of your normal cells will be empty/vacant.
Even a non-breaking space will do to avoid a cell from being targetted by the CSS rule above.
Needless to mention that you can adjust the space's height to whatever you like with the height property included.
Another possibility is to use a pseudo selector :after or :before
tr.highlight td:last-child:after
{
content: "\0a0";
line-height: 3em;
}
That might avoid issues with browser that don't understand the pseudo selectors, plus background-colors are not an issue.
The downside is however, that it adds some extra whitespace after the last cell.
For what is worth, I took advantage that I was already using bootstrap (4.3), because I needed to add margin, box-shadow and border-radius to my row, something I can't do with tables.
<div id="loop" class="table-responsive px-4">
<section>
<div id="thead" class="row m-0">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
</div>
<div id="tbody" class="row m-0">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
</div>
</section>
</div>
On css I added a few lines to mantain the table behavior of bootstrap
#media (max-width: 800px){
#loop{
section{
min-width: 700px;
}
}
}
add this style before the class="highlighted"
padding-bottom and
display is inline-table

Tables in IE do not have border when border = 0 in a css reset?

In my css file, I have a reset where I am setting the border:0. This causes all tables in IE, not firefox to have no border. Even if I set the border inline on the table, it still does not show in IE. Does anyone know the solution to this?
Part of the rest:
table, img
{
border:0;
}
<table border="1">
<tr>
<td></td>
</tr>
</table>
Border shows up in firefox, but not in IE. Do I have to do style="border:1px solid black" in the table instead of border="1"
If you want that specific table to have a border, I would just give it a class:
table, img
{
border:0;
}
table.something
{
border: solid 1px #000000;
}
<table class="something">
<tr>
<td></td>
</tr>
</table>
That should work in all browsers.
If you want a border you shouldn't set the border to 0. Try this instead:
table{
border: 2px;
}
That should work out better.
EDIT:
If you want to do it inline, you should do
<table border="2px">
Assuming that there's no typo in your code (in the question), have you tried adding a measurement unit to the inline setting?
<table border="1px">
For example?
Elsewise, try using CSS to re-/activate the borders:
<table style="border: 1px solid #000;"> <!-- or use a stylesheet, or style block, obviously -->
Have you checked that you're using a standards-compliant doctype declaration, and not lapsing into quirks-mode?
A couple standards-compliant ways to specify no border in css are:
border-width:0;
border-style:none;
Table elements, td elements and th elements all accept borders so a safe way to ensure no borders at all would be table, td, th {border-style:none;}.
table {border-collapse:collapse;} is a purely css way of removing spacing between cells
Check out w3schools.com or w3.org for standards-compliant css tips
Your example table has nothing in it. IE decides it has no content and so does not show the "border="1" attribute.
Reset with
table {
border:none;
}
Then use:
<table style="border:solid 1px #000;>
<tr><td>x</td></tr>
</table>
have you tried
table {border-collapse: collapse;}
EDIT: wait, you're trying to get rid of the border or add it? Now I'm confused...

Resources