I have a table I want to add a vertical-align to:
$output = '<style type="text/css">div.bar-container {border: 1px solid #ccc; width: 150px; margin: 2px 5px 2px 17px; padding: 3px; float: left; background: white; position:relative; border-radius: 4px;}div.bar-container div {background-color: #ff7021; height: 12px;}div.bar-container span {width:140px;text-align:center;float:left;font: normal 9px Arial,sans-serif;margin-top: 0px;}</style>
<span style="text-align: left"><h2>Control</h2></span><br />
' . $htmlarray["clientkeyautherror"] . '
<table width="100%" height="450px" cellspacing="0" cellpadding="0" class="frame">
<tr><td style="border:none">
<table width="100%" height="450px" border="0" cellpadding="10" cellspacing="0">
' . $htmlarray["displaystatus"] . '
' . $htmlarray["bandwidthbar"] . '
' . $htmlarray["memorybar"] . '
' . $htmlarray["hddbar"] . '
' . $htmlarray["buttons"] . '
' . $htmlarray["ips"] . '
' . $htmlarray["graphbutton"] . '
</table>
</td>
</tr>
</table>
';
return $output;
}
I need to add a vertical-align: middle; to the html array attributes such as memorybar. Can anyone show me how I would do this in the above example? Thanks!
I've tried this:
' "<div style='vertical-align:middle;'>" . ' . $htmlarray["displaystatus"] . ' . "</div>" '
but got the beautiful white page of death.
You can always put a class on the objects you want to affect or use :nth-child selector. For example like this, with using a class named 'middle' and the 1st child:
.middle{
vertical-align: middle;
background: green;
}
.frame td:nth-child(2){
background: brown;
vertical-align: middle;
}
Example in jsfiddle.
Also: Avoid using inline styles. It's bad practice.
EDIT1: Explanation on inline styles.
Consider the following:
Every character you insert, makes your page bigger, thus slower.
'style='vertical-align:middle' = 29 extra chars.
class='midtd' = 13 charts
that's a 16 char difference.
.midtd{vertical-align:middle;} = 30 chars.
if you need to apply the style to a single <td> inline yields 29 total chars, class yields 43 chars.
if you need to apply the style to 2 <td>s inline yields 58 total chars, class yields 56 chars.
if you need to apply the style to 3 <td>s inline yields 87 total chars, class yields 69 chars. And for every extra td, the difference grows bigger.
so if you need to apply it to more than 1 td, class is better than inlines, in terms of page size. It seems laughable but believe me you will thank me for this one at some point in your life ;).
Also, if you need to apply the style to an entire column, let's say the 2nd column, it costs you .frame td:nth-child(2){vertical-align:middle;} or 46 chars, independent of the amount of table rows.
In other words, nth-child is by far lighter than most solutions, but it is not suitable for random cells (let's say, you want to apply the style to the 3rd and the 5th cell on row 1, but only on the 4th cell on row 2, and like that the order is determined by server logic instead of a pater inside the table) for which the class method is by far lighter then inlines. And you can apply the same class to unlimited amount of elements.
this, and also, there is a great deal of people who think of your page less if it has 1 or 2 inline styles floating around.
Related
I tried a lot of solutions that I have found here and in Google, but no one of them works.
The table is dynamically generated by jQuery and Javascript.
Question:
How can I remove the padding, border between the cells in this html table ?
This is the HTML code:-
<div class="board">
<table id="tableGame">
</table>
</div>
This is the Css Code
.board{
float:left;
display: inline-block;
}
table{
border-collapse: collapse;
}
table tr, td{
border: 0px;
}
Javascript Code below
function mapGenerate(){
var map=createMap(); // this function returns a 2d array filled of random 1 and 0
/* example
map = [[1,1,1,1,0],
[1,0,0,0,0],
[1,0,1,1,1],
[1,0,0,0,1],
[1,1,1,0,1]]
*/
//loop the 2d array map and change the number with the appropriate img
for(var i = 0; i < map.length; i++) {
var innerArrayLength = map[i].length;
for(var j = 0; j<innerArrayLength; j++){
//loop the nested arrays so i can change the 1 and the 0 with the appropriate img
if(map[i][j] === 0){
map[i][j]="<img class=\"walkble\" src=\"mapTiles/floorResized.png\">"; //you can walk this part of the map
}else{
map[i][j]="<img class=\"nonWalkble\"// you cannot walk This part of the map src=\"mapTiles/volcanoresize.png\">";
}
;
}
$("#tableGame").append("<tr><td>"+ map[i] + "</td></tr>") // Here i print the elements of the array
}
}
mapGenerate();
Link to jsfiddle under here.
The problem is not about the 3rd white line ( it only appears in js fiddle, if I open it in my browser they looking as a normal table).
The problem is only to delete that disturbing padding between the cells.
jsfiddle
In codepen you will see it better, without lines error.
codepen
looks like the problem is on line 80 of your javascript.
$("#tableGame").append("<tr><td>"+ map[i] + "<td></tr>")
you're concat-ing an array (map[i]) into a string. javascript by default "stringify" it by joining it with commas.
The code above is like:
$("#tableGame").append("<tr><td>"+ map[i].join() + "<td></tr>")
since the default joining string is comma, that's equivalent to
$("#tableGame").append("<tr><td>"+ map[i].join(',') + "<td></tr>")
To get rid of the commas you simply joining it with an empty string
$("#tableGame").append("<tr><td>"+ map[i].join('') + "<td></tr>")
In HTML, there are attributes border, cellpadding, and cellspacing on the <table> element. Set them to 0. <table border="0" cellpadding="0" cellspacing="0">.
Border is for the border width.
Cellpadding is for the padding in the table cells.
Cellspacing is for the space between the table cells.
css:
table { border-collapse: collapse; }
table td { padding:0; }
I have a text area with one string binded to it. With the text color as white by default.
<textarea style="background-color: black;color:#fff;" [(ngModel)]="outputText"></textarea>
The bound string contains multiple variables.
return this.outputText = this.test1 + " test1Stat" + this.test2 + " test2Stat" + this.test3 + " test3Stat";
What I want to do is, if test1 is less than 1, it should show "test1 test1Stat" in red, while everything else is in green. Is there a way to do this?
It's not possible to color part of the text in a textarea,
However- you can try to use the 'contenteditable' property instead.
It basically turns your div into a textbox, and you can use html tags and such inside.
.greenText{
color:green;}
div{
border:black solid 1px;
padding:20px;
}
<div contenteditable="true">text text <span class='greenText'>GREEN TEXT</span> more text that you can edit</div>
I want my data to have an html that is rendered something like (imagine the headers are aligned above the values)
header1 header2 header3
List item 1
value111 value112 value113
value121 valueb122 valueb123
List item 2
value211 value212 value213
value221 valueb222 valueb223
I want the values to be part of the list block, so I can show/hide the content (collapse) on click. Further, I want the width of each 'column' to be dynamically decided, to accommodate the longest value (perhaps with a min width)
Unfortunately, the HTML table model is so simple that it does not let you enter headers for row groups, which seems to be what the list items would need to be, more or less. We need to fake a little: we form row groups with the tbody element and use the first row in a group as a group header. That row will contain the header in one cell that spans all columns.
The following example has minimal styling and one (rather clumsy) way of making the row group headers controls that can be used so switch off and on the display of data rows in the group. This is just a demonstration to show that such things are doable without mixing list markup with table markup (and, for that matter, without using list markup at all).
function toggleData(el) {
el.parentNode.parentNode.className =
el.parentNode.parentNode.className ? '' : 'hide';
}
tbody > tr:first-child > td:before {
content: '\2022';
padding-right: 0.25em;
}
tbody.hide > tr:not(:first-child) {
display: none;
}
<table border cellspacing=0>
<thead>
<tr><th>header1 <th>header2 <th>header3
</thead>
<tbody>
<tr><td colspan=3 onclick="toggleData(this)">List item 1
<tr><td>value111 <td>value112 <td>value113
<tr><td>value121 <td>valueb122 <td>valueb123
</tbody>
<tbody>
<tr><td colspan=3 onclick="toggleData(this)">List item 2
<tr><td>value211 <td>value212 <td>value213
<tr><td>value221 <td>valueb222 <td>valueb223
</tbody>
</tabe>
I need to apply a style class that will make a minumum margin to the right of labels. The tag is shown here with class "label-format":
echo '<p><span class="label-format">Make: </span>' . $term->name . '</p>';
echo '<p><span class="label-format">Model: </span>' . $term->name . '</p>';
echo '<p><span class="label-format">Condition: </span>' . $term->name . '</p>';
and I need to make it so that the values are pushed to the right like so (the periods represent whitespace):
Make:.........Ford
Model:........Focus
Condition:...New
the best I can get with margins is:
Make:...Ford
Model:...Focus
Condition:...New
A more maintainable option would simply be to use a table. For the <td>s containing the properties of $term, you could set text-align: left; and it will look the same.
You may use inline-block and whidth:
p span {
display:inline-block;
width:5em; /* here set width that you want*/
}
float:left; works too :)
Terr!
HTML::Table has pretty good flexibility to form HTML-tables from perl data structures, but i did not found proper way how to have th-tags different than ordinary cells (td) in same column. Or let me rephrase: if i set column class, i'd like to set it only for data rows, not for header row.
use strict;
use warnings;
use HTML::Table;
my $table = new HTML::Table(
-head=> ['one', 'two', 'eleven'],
-data=> [ ['yki', 'kaki', 'kommi'],
['yy', 'kaa', 'koo'] ]
);
$table->setColClass(1, 'class');
$table->setSectionColClass('tbody', 0, 2, 'class2');
print $table;
And output is:
<table>
<tbody>
<tr><th class="class">one</th><th class="class2">two</th><th>eleven</th></tr>
<tr><td class="class">yki</td><td class="class2">kaki</td><td>kommi</td></tr>
<tr><td class="class">yy</td><td class="class2">kaa</td><td>koo</td></tr>
</tbody>
</table>
Output i am looking for:
<table>
<tbody>
<tr><th>one</th><th>two</th><th>eleven</th></tr>
<tr><td class="class">yki</td><td class="class2">kaki</td><td>kommi</td></tr>
<tr><td class="class">yy</td><td class="class2">kaa</td><td>koo</td></tr>
</tbody>
</table>
There are section level methods, but th belongs also in tbody. Tables may be pretty complex, so i'd like to avoid iterating over the heading row and hope to find a decent way. Is there?
Might be easies to just tweak your CSS a bit. Presumably you have something like this in your stylesheet:
.class { /* Some pretty stuff */ }
So just change the selector to adjust how the header and body cells are styled:
td.class { /* The styles you want applied to body cells go here. */ }
th.class { /* And the styles for header cells (if any) go here. */ }
If you don't want any styling applied to the header cells then include the td.class { } bit in your stylesheet and leave the th.class { } out; there's nothing wrong with having a CSS class attached to an element that doesn't match anything in your stylesheets.