Multiple classes with barely the same name - html

I've got a little question and it seems there's no place on the internet where I can find the answer except here :p
So I've got an html page with some tables. Thoses tables have lines (as usual :p), and in those lines they are some inputs.
I want to add a rule in my css file wich have an effect on all those lines. Those lines have an id that is barely the same semantic.
Here's my code :
<table>
<tr id="tr_creneau_1">
<td>
<input />
</td>
</tr>
<tr id="tr_creneau_2">
<td>
<input />
</td>
</tr>
</table>
<table>
<tr id="tr_logo_1">
<td>
<input />
</td>
</tr>
</table>
At the end I want a css rule who impact all the inputs in the tr_* lines.

You can try with:
tr[id^="tr_"] input
But this is a css 3 selector and it doesn't work on all browsers, alternatively you can simply use:
tr input
or add a class to every row with that id and match that class

You can try:
tr[id^="tr_"] { --your css here-- }
It will check all of the tr tags if their id starts with tr_.
If it doesn't need to be at the start of the id attribute, just somewhere random , you can use:
tr[id*="tr_"]
If above doesn't work I would suggest going for a class based approach.

You could always add a CSS class to each table row you wish to target. e.g.
<table>
<tr id="tr_creneau_1" class="style-me">
<td>
<input />
</td>
</tr>
<tr id="tr_creneau_2" class="style-me">
<td>
<input />
</td>
</tr>
<tr id="somethingElse">
no input, so no class needed
</tr>
</table>
Then style as so:
table .style-me input {
background-color: red;
}

Related

Xpath to select tr based on specific td not containing text

I'm trying to write a ruby/selenium script to click the first check box in a table where the row does not contain certain values (plural) for //tr/td[6].
Each tr in the table is structured as follows:
<tr>
<td>
<input name = "checkbox" type = "checkbox"></input>
</td>
<td> irrelevant </td>
<td> irrelevant </td>
<td> irrelevant </td>
<td> irrelevant </td>
<td> text I care about </td>
</tr>
I need the xpath for the checkbox of the first tr in the table where//tr/td[6] does not contain "badtext" and does not contain "badtext2"
Not exactly sure how to write an xpath for this. Hopefully I explained this well enough.
You need to use the not(expression) function like this
//tr/td[6][not(contains(text(),'badtext'))][not(contains(text(),'badtext2'))]
and your final xpath would be like this
//tr/td[6][not(contains(text(),'badtext'))][not(contains(text(),'badtext2'))]/../td/input[#name='checkbox']
if you want to filter any attribute including text, use
contains(.,'badtext')

Xpath to an element with two different contains text

I have the next HTML and i have this xpath to find the "Show":
xpath=//*[#id="Some_id"]/div/table/tbody/tr/td[contains(text (), "Show")]
and it works, but i need to find "Show" of a particular item, in this matter of a "Main" item, so i need smth like this:
xpath=//*[#id="Some_id"]/div/table/tbody/tr/td[contains(text (), "Show")]/preceding-sibling::td[contains(text (), "Main")]
but it doesn't work. Thanks
<tr class="even">
<td title="Main">
<strong>Main</strong>
</td>
<td>
text/html
</td>
<td>
Another text
</td>
<td>
Some text here
</td>
<td>
No
</td>
<td>
Show
</td>
</tr>
You can try this xpath. This will first select a tr element which contains the specific td and then select the required a tag.
"//tr[#class='even' and td[#title='Main']]/a[text()='Show']"
EDIT: This xpath worked for the OP
"//*[#id='Some_id']/div[1]/table/tbody/tr[#class='even']/td/a[contains(text (), 'Show')]"
You want to find "Show" that belong to the "Main" row in the table.
Here is what i would do
xpath=//td[#title='Main']/following-sibling::td[contains(text(), 'Show')]
More on xpath axes: http://www.w3schools.com/xsl/xpath_axes.asp

HTML/CSS, getting table cells to balance

I have a table formatted as:
<table>
<tr>
<td>
Long list of info
Line two
</td>
<td>
Shorter list of info
</td>
</tr>
</table>
How can I get them to both display from the top of 'tr'? I assume there's a way to stop automatic vertical alignment with CSS?
To clarify for future viewers, I got it working using:
CSS:
td {
vertical-align: top;
}
HTML:
<table>
<tr>
<td>
Long list of info
Line two
</td>
<td>
Shorter list of info
</td>
</tr>
</table>
(Here's the fiddle)
Hey if you have some questions how to use tables pls look some examples here
http://www.w3schools.com/html/html_tables.asp
http://www.w3schools.com/css/css_table.asp
If you prefer to avoid CSS you can do the same thing inline with the depreciated valign tag. Valign is not supported in HTML5 but is the recommended method if you are working within the context of an HTML email.
<table border="1">
<tr>
<td width="110">
Long list of info Line two
</td>
<td valign="top">
Shorter list of info
</td>
</tr>
</table>
Or you could always use two rows if you can predict and control where your breaks are going to be and want to simplify the markup further.

CSS to mimic simple table within div

I have used some AJAX to output HTML to a div.
I thought the AJAX would let me display a table, but since it outputs to a div, turns out, it does not. <td> codes etc. are ignored. I know that table-less display is considered better, anyway, however I am very weak in CSS.
Can anyone suggest how to display the following simple output without tables. I mainly need to make columns line up when text is different length.
HTML
<div id="displayhere"></div>
Output I would like to go into div except not sure how to put table in div:
<tr><td colspan=2>Heading</td></tr>
<tr><td>Short text option 1</td><td><input type="checkbox"></td></tr>
<tr><td>Really long text Option 2</td><td input type="checkbox"></td></tr>
All you need to do, in simplified form is:
var output = '<tr><td colspan=2>Heading</td></tr><tr><td>Short text option 1</td><td><input type="checkbox"></td></tr><tr><td>Really long text Option 2</td><td><input type="checkbox"></td></tr>',
table = $('<table />').appendTo('#displayhere'),
tbody = $('<tbody />').html(output).appendTo(table);
JS Bin demo.
You can have tables inside div tags..the following works fine
<div id="displayhere">
<table>
<tr>
<td colspan=2>Heading</td>
</tr>
<tr>
<td>Short text option 1</td>
<td><input type="checkbox"></td>
</tr>
<tr>
<td>Really long text Option 2</td>
<td> <input type="checkbox"></td></tr>
</table>
</div>
As #DavidThomas implies, you can have an HTML table inside a <div>, you just can’t have <tr> tags without wrapping them in a <table> tag.
I’d note that the HTML you want to insert can also be improved in a couple of ways:
There is a tag for heading cells inside tables: <th>. If the heading applies to several rows, then you should wrap those rows in a <tbody> tag, and set the scope attribute of the <th> to rowgroup
When you’re labelling a form control, you should wrap the label text in a <label> element, and set the <label>’s for attribute to the id of its form control.
Here’s the improved code. Screen reader users will find it easier to deal with this code:
<tbody>
<tr>
<th scope="rowgroup" colspan="2">Heading</th>
</tr>
<tr>
<td><label for="option1">Short text option 1</label></td>
<td><input id="option1" type="checkbox"></td>
</tr>
<tr>
<td><label for="option2">Really long text Option 2</label></td>
<td><input id="option2" type="checkbox"></td>
</tr>
</tbody>

Colspan in IE7/8 not respected

The DOM looks like this:
<table>
<tr>
<td>a</td>...<td>g</td>
</tr>
<tr>
<td colspan="3">
<table>
...
</table>
</td>
</tr>
<tr>
<td></td>...<td></td>
</tr>
</table>
Any idea why this wouldn't work in IE? I tried setting width:auto on the TD holding the inner table, and table-layout:fixed isn't viable because the tabular data is generated dynamically.
What could be going wrong?
Currently, the table only fills the first column, and it will not span.
Update: EXAMPLE
http://stefankendall.com/files/example.html
Use colSpan, not colspan
The only thing that comes to mind is that you may have to fill the columns with something for them to get rendered in IE.
<td> </td>