grey border surrounding image - html

I have a Bootstrap table on the view and the last 2 columns are images. I load the table once the Ajax call is successful.
Issue
when table id populated with data, I see grey border and nothing makes sense. I don't have any code which specifies border.
Below is my CSS Code
img {
border:none;
}
table {
border-collapse:collapse;
}
.assign {
background: url(Images/user_not_assigned.png) no-repeat;
width:100%;
height:40px;
}
I added blue dashed border to the image to make sure it overrides. I see the blue dashed border along with grey border
CSS
img {
border : 2px blue dashed;
border-radius:10px;
padding:5px;
}
table {
border-collapse:collapse;
}
.assign {
background: url(Images/user_not_assigned.png) no-repeat;
width:100%;
height:40px;
}
HTML View:
<div id="getorder" class="table-responsive" data-request-url="#Url.Action("GetPendingOrders", "Main")">
<table id="editorder" class="table table-striped table-hover">
<caption><h4 class="chocolatetext"><strong>Pending / Assigned Orders</strong></h4></caption>
<thead>
<tr>
<th>COL1 #</th>
<th>COL2 #</th>
<th>COL3 #</th>
<th>Assign</th>
<th>Update</th>
</tr>
</thead>
<tbody id="assignorder" data-request-url="#Url.Action("AssignOrder", "Main")">
</tbody>
</table>
</div>
#Scripts.Render("~/Scripts/Custom/main.js")
Jquery Code to load table
$.ajax({
type: 'GET',
url: peningorderurl,
traditional: true,
cache: false,
success: function (data) {
var table = $("table");
table.find("tr:gt(0)").remove(); //remove all previous rows if needed
$.each(data, function (index, element) {
var tr = $("<tr class='clickable-row' data-href=" + element.id + " data-row=" + element.orderno + "></tr>");
table.append(tr);
var td = $("<td>" + element.id + "</td>");
tr.append(td);
var td = $("<td class='testno'>" + element.testno + "</td>");
tr.append(td);
var td = $("<td class='screenno'>" + element.screenno + "</td>");
tr.append(td);
var assignimage = ('<img class="assign assignselected" alt:"Assign Image" />');
if (element.assigned == true) {
assignimage = ('<img class="assigned assignselected" alt:"Assign Image" />');
}
var td = $("<td>" + assignimage + "</td>");
tr.append(td);
assignimage = ('<img class="no-testresults editselected" alt:"Update Test Results" />');
var td = $("<td>" + assignimage + "</td>");
tr.append(td);
});
},
error: function (err) {
alert("Ajax failed:");
console.log(err);
}
});
Question
How do I remove this grey border? Any help would be appreciated.

Change your table CSS to:
table {
border:0;
}

add border 0 on table
table {
border-collapse:collapse;
border:0;
}

Could be background colour coming through?
td {
background-color: #fff;
padding: 0;
}
img {
margin: 0;
display: block;
}

Try using exact specificity for that vs just targeting the table, so try this:
table thead > tr > th { border: none; }

I had the same issue and finally figured it out. The combination of an img Tag and the background property causes this issue. Either use the img tag with src= or use another tag.
Answer found here: css "background-image" shows unwanted border, img "src" does not

Related

CSS nth-chlld that works with only visible elements? [duplicate]

This question already has answers here:
Select odd even child excluding the hidden child
(9 answers)
Closed 5 months ago.
I get that :nth-child is actually checking "children" vs "visible children" but is there a selector that would work with visible children?
Imagine I have table, I make odd rows a different color
I have a search filter that hides rows that don't match the search. Now when I search the rows are no longer alternating colors.
Of course I can go add/remove classes to every element which I'm basically doing already to hide/show them but I thought I'd ask if there was a CSS way to do it.
const searchElem = document.querySelector('input');
const tableElem = document.querySelector('table');
function search() {
const str = searchElem.value.toLowerCase();
const rows = tableElem.querySelectorAll('tr');
rows.forEach(function(row){
const text = row.textContent.toLowerCase();
if (str.length && !text.includes(str)) {
row.classList.add('hide');
} else {
row.classList.remove('hide');
}
});
}
searchElem.addEventListener('keyup', search);
tr {
background-color: #CDF;
}
tbody>tr:nth-child(odd) {
background-color: #DEF;
}
thead>tr {
background-color: lightgreen;
}
.hide {
display: none;
}
<input type="search" placeholder="search">
<table>
<thead>
<tr><td>Name</td><td>Amount</td></tr>
</thead>
<tbody>
<tr><td>Apple</td><td>220</td></tr>
<tr><td>Watermelon</td><td>465</td></tr>
<tr><td>Orange</td><td>94</td></tr>
<tr><td>Pear</td><td>567</td></tr>
<tr><td>Cherry</td><td>483</td></tr>
<tr><td>Strawberry</td><td>246</td></tr>
<tr><td>Nectarine</td><td>558</td></tr>
<tr><td>Grape</td><td>535</td></tr>
<tr><td>Mango</td><td>450</td></tr>
<tr><td>Blueberry</td><td>911</td></tr>
<tr><td>Pomegranate</td><td>386</td></tr>
<tr><td>Carambola</td><td>351</td></tr>
<tr><td>Plum</td><td>607</td></tr>
<tr><td>Banana</td><td>292</td></tr>
<tr><td>Raspberry</td><td>912</td></tr>
<tr><td>Mandarin</td><td>456</td></tr>
<tr><td>Jackfruit</td><td>976</td></tr>
<tr><td>Papaya</td><td>200</td></tr>
<tr><td>Kiwi</td><td>217</td></tr>
<tr><td>Pineapple</td><td>710</td></tr>
<tr><td>Lime</td><td>983</td></tr>
<tr><td>Lemon</td><td>960</td></tr>
<tr><td>Apricot</td><td>647</td></tr>
<tr><td>Grapefruit</td><td>861</td></tr>
<tr><td>Melon</td><td>226</td></tr>
<tr><td>Coconut</td><td>868</td></tr>
<tr><td>Avocado</td><td>385</td></tr>
<tr><td>Peach</td><td>419</td></tr>
</tbody>
</table>
There is no selector but if you are open to a specific solution for this case then you can rely on gradient like below:
const searchElem = document.querySelector('input');
const tableElem = document.querySelector('table');
function search() {
const str = searchElem.value.toLowerCase();
const rows = tableElem.querySelectorAll('tr');
rows.forEach(function(row){
const text = row.textContent.toLowerCase();
if (str.length && !text.includes(str)) {
row.classList.add('hide');
} else {
row.classList.remove('hide');
}
});
}
searchElem.addEventListener('keyup', search);
thead>tr {
background-color: lightgreen;
}
.hide {
display: none;
}
table {
position:relative; /* relative to all the table */
z-index: 0;
}
td {
line-height: 1.2em; /* the height */
clip-path: inset(0); /* clip the pseudo element to td */
}
tbody td:before {
content: "";
position: absolute;
z-index: -1;
inset: 0;
background:
repeating-linear-gradient(
#CDF 0 calc(1.2em + 4px), /* height + 2*border-spacing */
#DEF 0 calc(2.4em + 8px) /* 2*height + 4*border-spacing */
);
}
<input type="search" placeholder="search">
<table>
<thead>
<tr><td>Name</td><td>Amount</td></tr>
</thead>
<tbody>
<tr><td>Apple</td><td>220</td></tr>
<tr><td>Watermelon</td><td>465</td></tr>
<tr><td>Orange</td><td>94</td></tr>
<tr><td>Pear</td><td>567</td></tr>
<tr><td>Cherry</td><td>483</td></tr>
<tr><td>Strawberry</td><td>246</td></tr>
<tr><td>Nectarine</td><td>558</td></tr>
<tr><td>Grape</td><td>535</td></tr>
<tr><td>Mango</td><td>450</td></tr>
<tr><td>Blueberry</td><td>911</td></tr>
<tr><td>Pomegranate</td><td>386</td></tr>
<tr><td>Carambola</td><td>351</td></tr>
<tr><td>Plum</td><td>607</td></tr>
<tr><td>Banana</td><td>292</td></tr>
<tr><td>Raspberry</td><td>912</td></tr>
<tr><td>Mandarin</td><td>456</td></tr>
<tr><td>Jackfruit</td><td>976</td></tr>
<tr><td>Papaya</td><td>200</td></tr>
<tr><td>Kiwi</td><td>217</td></tr>
<tr><td>Pineapple</td><td>710</td></tr>
<tr><td>Lime</td><td>983</td></tr>
<tr><td>Lemon</td><td>960</td></tr>
<tr><td>Apricot</td><td>647</td></tr>
<tr><td>Grapefruit</td><td>861</td></tr>
<tr><td>Melon</td><td>226</td></tr>
<tr><td>Coconut</td><td>868</td></tr>
<tr><td>Avocado</td><td>385</td></tr>
<tr><td>Peach</td><td>419</td></tr>
</tbody>
</table>

Change the HTML of an Expanding Row

I am looking to have a + change to a - when my table row expands. I have provided my code below and also through JS Fiddle here: https://jsfiddle.net/k37f0cbp/2/
$(document).ready(function() {
$('tr.parent')
.css("cursor", "pointer")
.attr("title", "click")
.click(function() {
$(this).siblings('.child-' + this.id).toggle();
});
$('tr[#class^=child-]').children('td').hide();
});
$if(('tr[#class^=child-]').is(":visible")).click(function() {
$('.plus', this).html('-');
});
th,
td {
border-bottom: 1px solid black;
}
th,
td {
padding: 15px;
}
tr:hover {
background-color: #f5f5f5;
}
[class*='child-row'] {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table style="width:100%">
<tbody>
<tr class="parent" id="row1" title="click">
<td><span class="plus">+</span></td>
<td>Paper Idea One</td>
</tr>
<tr class="child-row1">
<td>testing</td>
</tr>
</tbody>
</table>
$(document).ready(function ()
{
//add a flag
var expanded = false;
$('tr.parent')
.css("cursor", "pointer")
.attr("title", "click")
.click(function ()
{
$(this).siblings('.child-' + this.id).toggle();
//check flag, update value of a button and update a flag
if(expanded)
{
$(".plus").text("+");
expanded = false;
}
else
{
$(".plus").text("-");
expanded = true;
}
});
$('tr[#class^=child-]').children('td').hide();
});
$if (('tr[#class^=child-]').is(":visible")).click(function()
{
$('.plus', this).html('-');
});
After many more hours exploring this, I combined what the contributor above added with some other things I experimented with and came up with a more elegant and accurate answer that accounts for multiple rows. The only trick here is adding an id to the plus element that is equivalent to the parents id.
$(document).ready(function ()
$('tr.parent')
.css("cursor", "pointer")
.attr("title", "click")
.click(function ()
{
$(this).siblings('.child-' + this.id).toggle();
var s = this.id;
if ($(this).next().is(":visible")) {
$('#' + s + '.plus').html('-');
}
if ($(this).next().is(":hidden")) {
$('#' + s + '.plus').html('+');
}
})
)};

Cannot remove padding in table

I am trying to remove the padding from the cells inside my table. I have set it to not have padding in the relevant CSS selectors but not a success.
As you can see, there is padding on all of these cells.
I would like there to not be. I have tried various different padding settings and changing the vertical alignment makes no difference other than to move the text, the padding just goes from all at the bottom to spread between bottom and top.
Below is the code:
'use strict'
let table = document.getElementById("mainTable")
let rows = table.querySelectorAll("tbody tr")
let columns = table.querySelectorAll("#weeks th")
for (let row of rows) {
for (let o = 0; o<columns.length-1; o++) {
let cell = document.createElement("td")
cell.innerHTML='&nbsp'
cell.addEventListener("click", function() {
if (cell.getElementsByTagName("input")[0]) { return } //If cell currently has an input box
//
let oldValue = ""
if (cell.innerHTML !== " ") { //if cell has a saved value
oldValue = cell.innerHTML
}
cell.innerHTML = '<input type="text" class="cellInputs">'
//update input box with old value and focus it
cell.getElementsByTagName("input")[0].focus()
cell.getElementsByTagName("input")[0].value = oldValue
cell.getElementsByTagName("input")[0].addEventListener("keypress", function(e) {
if (e.keyCode === 13) {
cell.innerHTML=cell.getElementsByTagName("input")[0].value
e.preventDefault()
return true
}
})
cell.getElementsByTagName("input")[0].addEventListener("input", function(e) {
console.log(e)
let cellValue = cell.getElementsByTagName("input")[0].value
if (e.data === "." && (cellValue.split('.').length-1 > 1 || cellValue === ".")) {
console.log("stop")
cell.getElementsByTagName("input")[0].value = (cellValue).substring(0, cellValue.length - e.data.length)
}
if (isNaN(e.data) && e.data !==".") {
console.log("Stop")
cell.getElementsByTagName("input")[0].value = (cellValue).substring(0, cellValue.length - e.data.length)
}
//store value inputted into the actual cell
})
cell.getElementsByTagName("input")[0].addEventListener("paste", function(e) {
// clipboardData = e.clipboardData || window.clipboardData;
// pastedData = clipboardData.getData('Text');
let cellValue = cell.getElementsByTagName("input")[0].value
if (cellValue !== "") {
e.preventDefault()
return false
}
if (e.clipboardData.getData('text') === "." && (cellValue.split('.').length-1 > 1 || cellValue === ".")) {
e.preventDefault()
return false
}
if (isNaN(e.clipboardData.getData('text')) && e.clipboardData.getData('text') !==".") {
e.preventDefault()
return false
}
//store value inputted into the actual cell
})
cell.getElementsByTagName("input")[0].addEventListener("focusout", function() {
console.log(document.activeElement)
cell.innerHTML=cell.getElementsByTagName("input")[0].value
})
})
row.appendChild(cell)
}
}
*{
padding: 0;
margin: 0;
font-family: "Trebuchet MS", Times, serif;
box-sizing:border-box;
}
html{
background-color: #35454E;
overflow: hidden;
}
html *{
font-family: "Work Sans", Arial, sans-serif !important;
color: white !important;
}
table{
border-collapse: collapse;
border-spacing: 0px;
color:#35454E;
height:100%;
width:100%;
}
table, th{
border: 2px solid white;
padding:0;
}
th{
vertical-align:top;
font-size: 2.5vw;
}
td{
vertical-align:top;
box-sizing:border-box;
position: relative;
border: 2px solid white;
padding:0;
text-align: center;
font-size: 2.5vw;
padding:0;
}
.cellInputs{
position: absolute;
width:100%;
height:100%;
display: block;
top:0;
left:0;
border:none;
text-align: center;
background-color: #35454E;
word-wrap: break-word;
font-size: 2.5vw;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="MMS.css">
<title>Money Management</title>
</head>
<body>
<table id="mainTable">
<thead>
<tr>
<th>2019</th>
<th colspan="5">January</th>
</tr>
<tr id="weeks">
<th>&nbsp</th>
<th>31/12/2018</th>
<th>07/01/2019</th>
<th>14/01/2019</th>
<th>21/01/2019</th>
<th>28/01/2019</th>
</tr>
</thead>
<tbody>
<tr>
<th>Balance</th>
</tr>
<tr>
<th>Pay</th>
</tr>
<tr>
<th>&nbsp</th>
</tr>
<tr>
<th>Rent</th>
</tr>
<tr>
<th>Food</th>
</tr>
<tr>
<th>&nbsp</th>
</tr>
<tr>
<th>Total</th>
</tr>
</tbody>
</table>
</body>
<script src="MMS.js"></script>
</html>
Remove height:100% from table .

How to parse JSON API Link to HTML Table

I'm trying to parse an API json file to an HTML table, i posted the contents of the JSON API file in here for reference: https://pastebin.com/raw/jWaET2TU
For start i wanted to make it simple, just 3 values.
ID | NAME | DESCRIPTION
I can print all data, then when I try to fetch individual values or i get an error or a blank page.
This is all i have till now, but can't figure out what's wrong in the code.
.HTML
<table id="personDataTable">
<tr>
<th>ID</th>
<th>NAME</th>
<th>DESCRIPTION</th>
</tr>
</table>
<style>
table {
border: 2px solid #666;
width: 100%;
}
th {
background: #f8f8f8;
font-weight: bold;
padding: 2px;
}
</style>
.JS
$.ajax({
url: 'https://apiexample.com',
type: "get",
dataType: "json",
success: function(data) {
drawTable(data);
}
});
function drawTable(data) {
for (var i = 0; i < data.length; i++) {
drawRow(data[i]);
}
}
function drawRow(rowData) {
var row = $("<tr />")
$("#personDataTable").append(row);
row.append($("<td>" + rowData.id + "</td>"));
row.append($("<td>" + rowData.name + "</td>"));
row.append($("<td>" + rowData.headline + "</td>"));
}

CSS Table Column Freeze

Could someone help with this
http://jsfiddle.net/smilepak/8qRQB/4/
<div>
<table>
<tr>
<td class="headcol">Fiddle Options</td>
<td class="long">Created and maintained by Piotr and Oskar. Hosted by DigitalOcean. Special thanks to MooTools community.</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">Legal, Credits and Links</td>
<td class="long" style="width:300px">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long" style="width:300px">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">Ajax Requests</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
</table>
table {
border-collapse:separate;
border-top: 1px solid grey;
}
td {
margin:0;
border:1px solid grey;
border-top-width:0px;
}
div {
width: 600px;
overflow-x:scroll;
margin-left:10em;
overflow-y:visible;
padding-bottom:1px;
}
.headcol {
position:absolute;
width:10em;
left:0;
top:auto;
border-right: 1px none black;
border-top-width:1px;
/*only relevant for first row*/
margin-top:-3px;
/*compensate for top border*/
}
In firefox, the row border doesn't seem to line up. I want a table where the first column is frozen while the rest is scrollable. All rows are linked up to a single scroll bar so i can use in a loop via Razor view in MVC.
Thanks,
JSBIN: http://jsbin.com/IwisANaX/3/edit
CSS
...
.freeze td:nth-child(1),
.freeze th:nth-child(1) {
background: #ddd;
position: absolute;
width: 20px;
left: 0;
}
.freeze .bottomScroll {
overflow-x: hidden;
margin-left: 20px;
}
...
JS
var ns = $('.newScroll', table),
bs = $('.bottomScroll', table);
ns.scroll(function(){bs.scrollLeft(ns.scrollLeft());});
try using
.headcol {max-width: 10em}
also note that using
.headcol {position: absolute}
makes the cell not to align relatively to the document; that´s why it looks like that
I used this combination of JavaScript and CSS to solve the sticky column issue.
https://jsfiddle.net/5poxyje4/
JS (Commented Section has boostrap compatible code)
var $table = $('.table');
var $fixedColumn = $table.clone().insertBefore($table).addClass('fixed-column');
$fixedColumn.find('th:not(:first-child),td:not(:first-child),.excludeHeader').remove();
$fixedColumn.find('tr').each(function (i, elem) {
if(elem.rowSpan = "1"){
$(this).height($table.find('tr:eq(' + i + ')').height());
}
else{
for (x = i; x <= parseInt(elem.rowSpan); x++) {
var tempHeight = $(this).height() + $table.find('tr:eq(' + x + ')').height();
$(this).height(tempHeight);
}
}
});
//Comments for if you are using bootrap tables
//var $table = $('.table');
//var $fixedColumn = $table.clone().insertBefore($table).addClass('fixed-column');
//$fixedColumn.find('th:not(:first-child),td:not(:first-child),.excludeHeader').remove();
//$fixedColumn.find('tr').each(function (i, elem) {
// $fixedColumn.find('tr:eq(' + i + ') > th:first-child,tr:eq(' + i + ') > td:first-child').each(function (c, cell) {
// if (cell.rowSpan == "1") {
// $(this).height($table.find('tr:eq(' + i + '),tr:not(.excludeRow)').height());
// }
// else {
// for (x = 1; x < parseInt(cell.rowSpan) ; x++) {
// var tempHeight = $(this).height() + $table.find('tr:eq(' + x + ')').height();
// $(this).height(tempHeight);
// }
// }
// $(this).width($table.find('.stickyColumn').first().width());
// });
//});
CSS(Commented section has bootstrap compatible code in my Site.css)
.table-responsive>.fixed-column {
position: absolute;
display: inline-block;
width: auto;
border-right: 1px solid #ddd;
/* used z-index with bootstrap */
/*z-index: 9999;*/
}
/*This media query conflicted with my bootstrap container. I did not use it*/
#media(min-width:768px) {
.table-responsive>.fixed-column {
display: none;
}
}
/*Commented Section for if you are using bootstrap*/
/*.table-responsive>.fixed-column {
position: absolute;
display: inline-block;
width: auto;
border-right: 1px solid #ddd;
background-color:#ffffff;
}*/
This accounts for if a th or a td has a rowspan greater than 1 as well.