HTML table styling and layout - html-table

I'm trying to create a basic layout or four tables which sit side by side (with a small margin between the tables. Each table will have one row in the top section containing a currency symbol which will stretch the full length of the table and then below a second row will be subdivided into two cells with an input box and submit button.
There are two issues which I can't seems to find a solution for:
The top row divides into two cells. This means when the symbol is centered it centers to the left cell as opposed to the centre of the table (top row should stretch the full width of the table)
The row/ cells below contain a large amount of empty space above the input box and button which I can't seem to remove (have tried setting margin / borders to 0 etc.
Here is the code (borders added for clarity):
HTML
<table id = "pound_table">
<tr>
<td id = "pound_symbol">£</td>
</tr>
<tr id = "input">
<td id = "input"><input type = "text" name = "pound" size = "6" /></td>
<td><input type = "submit" value = "CONVERT" /></td>
</tr>
</table>
<table id = "euro_table">
<tr>
<td id = "euro_symbol">€</td>
</tr>
<tr>
<td><input type = "text" name = "euro" size = "6" /></td>
<td><input type = "submit" value = "CONVERT" /></td>
</tr>
</table>
<table id = "dollar_table">
<tr>
<td id = "dollar_symbol">$</td>
</tr>
<tr>
<td><input type = "text" name = "dollar" size = "6" /></td>
<td><input type = "submit" value = "CONVERT" /></td>
</tr>
</table>
<table id = "yen_table">
<tr>
<td id = "yen_symbol">¥</td>
</tr>
<tr>
<td><input type = "text" name = "yen" size = "6" /></td>
<td><input type = "submit" value = "CONVERT" /></td>
</tr>
</table>
CSS
table
{
border-spacing: 0px;
border: 1px solid black;
margin-right:20px;
}
tr {
margin: 0;
padding:0;
border-spacing: 0px;
border: 1px solid black;
}
td {
border: 1px solid black;
margin: 0;
padding:0;
border-spacing: 0px;
}
#pound_symbol,
#euro_symbol,
#dollar_symbol,
#yen_symbol
{
text-align: center;
}
#pound_table,
#euro_table,
#dollar_table,
#yen_table
{
display: inline-block;
font-size:72px;
}
also see the fiddle;
http://jsfiddle.net/qs0dehhx/1/

Fixed, take a look: https://jsfiddle.net/zer00ne/aonc6we7/1/
HTML
For the the first row: <td colspan="2" id=...>
CSS
input { display: block; min-height: 100%; }

Related

LINQ-to-XML in HtmlAgilityPack to select TR

This may straightforward for someone, so if you are that one please take a look at this:
I have a table with more rows, but one row I want to extract based on a given text, here is the table excerpt:
... <tr>
<td class="border-1px-solid-black" colspan="1">
<img onclick="PopupCenter('{{InvoiceDetails.0.Link}}')" style="max-height: 35px; max-width: 35px; cursor: pointer;" src="/images/report.png" /></td>
<td class="border-1px-solid-black" colspan="11">
<p>{{InvoiceDetails.0.Description}}</p>
</td>
<td class="border-1px-solid-black" colspan="2" style="text-align: right;">
<p>{{InvoiceDetails.0.Quantity}}</p>
</td>
<td class="border-1px-solid-black" colspan="2" style="text-align: right;">
<p>{{InvoiceDetails.0.Amount}} </p>
</td>
</tr>...
I am using HtmlAgilityPack and VB.NET and I want to get TR that contains InvoiceDetails.0 in any element.
How to do it?
Thanks!
I will post the way I've finished this, but this is not the shortest way:
nodes = doc.DocumentNode.SelectNodes("//*[text()[contains(., '" + find + "')]]")
If nodes IsNot Nothing Then
node = nodes(0)
While node.ParentNode.Name <> "tr"
node = node.ParentNode
End While
node = node.ParentNode
'and here I have reference to TR node
Next
End If
If you have shorter way please write here.

nowrap on td in table but not if colspan

Is it possible to control nowrap of table cells depending on if the cell (td) has a colspan attribute or not?
Current css
.k2table {table-layout: fixed; width:100%;border-collapse: collapse}
.k2table tr {height:18px}
.k2table td {text-align: left;padding:1px;white-space: nowrap;}
.k2table td+td {text-align: right;width:70px;}
.k2table td+td+td {text-align: right;width:70px;}
If I have a table such as below I don't want nowrap on the td with colspan.
<table class="k2table">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
</table>
You can do that using an [attr] selector
.k2table td[colspan] { white-space: normal }
If you need to be more specific you can apply your style just to the cell with THAT colspan
.k2table td[colspan="3"] { white-space: normal }

PHP selenium find parent sibiling

I have below code and I want find second td value. How can I select text with <br/> in it?
<tr>
<td valign="top" style="width: 85px">
<span class="fieldtext">Address:</span>
</td>
<td valign="top">
Shaftesbury House, 1st floor
<br/>20 Tylney Road
<br/>Bromley
<br/>Greater London
<br/>BR1 2RL
<br/>United Kingdom
<br/>
</td>
<td style="width: 200px; vertical-align: top; text-align: right;" rowspan="2" />
</tr>
Assuming you want to find the td element by the Address: label defined previously, you can use the following-sibling axis:
//td[span = 'Address:']/following-sibling::td
Then, after locating the element, call getText() method:
$driver->findElement(WebDriverBy::xpath("//td[span = 'Address:']/following-sibling::td"))->getText();
Try as below :-
$driver->findElement(WebDriverBy::xpath('//tr/td[2]'))->getText();
Hope it helps....:)

Alternating row colors in a ForEach loop

My foreach code
Notice that my second row has a different background color.
#foreach (var item in Model.fNameList)
{
<tr>
<td style ="background-color:#E0EBEB; height:40px;width:100px;"> T-00001</td>
<td style ="background-color:#E0EBEB; height:40px;width:200px;"> #item.firstName</td>
</tr>
<tr>
<td style ="background-color:#fff; height:40px;width:100px;"> T-00001</td>
<td style ="background-color:#fff; height:40px;width:200px;"> #item.firstName</td>
</tr>
}
I want my second TR tag to have the second value of my "FIRSTNAME", example: if var item[0] is "FIRSTNAME" = "GEM", and var item[1] is "FIRSTNAME" = "DIAMOND". now if I run my code, the value of my first TR tag has "FIRSTNAME" = "GEM" while in the second TR tag the value is "FIRSTNAME" = "GEM" as well. Now I want my second TR tag to have the value: "FIRSTNAME" = "DIAMOND".
EDIT
Ok, I understand your issue more now, you are wanting to do alternating row colors. The best way to do that is to set a variable that allows you to know if you are alternating or not. I have updated my example to show this.
Then, you only need one set of <tr> in your foreach loop then. Each item will output exactly one <tr>.
#{
var altRow = false;
foreach (var item in Model.fNameList)
{
<tr>
<td style ="background-color:#(altRow ? "#fff" : "#E0EBEB"); height:40px;width:100px;"> T-00001</td>
<td style ="background-color:#(altRow ? "#fff" : "#E0EBEB"); height:40px;width:200px;"> #item.firstName</td>
</tr>
altRow = !altRow;
}
}
What this does is switches the altRow variable from true to false on each iteration through the foreach loop. When true, it will set the background color to #fff and when false, #E0EBEB
So - if we walk through this code with the following data:
item[0].FirstName = "Gem"
item[1].FirstName = "Diamond"
Then the expected output will be
<tr>
<td style ="background-color:#E0EBEB; height:40px;width:100px;"> T-00001</td>
<td style ="background-color:#E0EBEB; height:40px;width:200px;">Gem</td>
</tr>
<tr>
<td style ="background-color:#fff; height:40px;width:100px;"> T-00001</td>
<td style ="background-color:#fff; height:40px;width:200px;">Diamond</td>
</tr>

webdriver why the table can get its size but canot get its text

the pagesource:
<TABLE class=mini-listbox-items style="WIDTH: 100%" cellSpacing=0 cellPadding=0>
<TBODY>
<TR class="mini-listbox-item mini-listbox-item-selected" id=mini-45$0 index="0">
<TD class=mini-listbox-checkbox><INPUT id=mini-45$ck$0 type=checkbox CHECKED></TD>
<TD class="">xx</TD></TR>
<TR class=mini-listbox-item id=mini-45$1 index="1">
<TD class=mini-listbox-checkbox><INPUT id=mini-45$ck$1 type=checkbox></TD>
<TD class="">yy</TD></TR></TBODY></TABLE></DIV><INPUT type=hidden value=Y></DIV>
<DIV class=mini-errorIcon></DIV></DIV></DIV>
<DIV class=mini-shadow style="DISPLAY: none; Z-INDEX: 1002; LEFT: 393px; WIDTH: 78px; TOP: 326px; HEIGHT: 46px"></DIV></BODY>
my code:
driver.findElements(By.xpath(("//td[#class='mini-listbox-checkbox']/following-sibling::td[position()=1]"))).size();
driver.findElements(By.xpath(("//td[#class='mini-listbox-checkbox']/following-sibling::td[position()=1]"))).get(0).getText();
the first line,it prints 2,then the second line,it prints none,why?
Your logic is working fine.
int n=driver.findElements(By.xpath(("//td[#class='mini-listbox-checkbox']/following-sibling::td[position()=1]"))).size();
String s=driver.findElements(By.xpath(("//td[#class='mini-listbox-checkbox']/following-sibling::td[position()=1]"))).get(0).getText();
System.out.println(n+"======>>"+s);
The above code is giving correct output only.
2======>>xx