2

I want to target the following item:

/html/body/div[2]/div/div[5]/div/table/tbody/tr[2]/td[2]/img

how can i style this exactly?

Currently i have this css which seems to apply the style to all img inside the div

div.PageHeaderDescription img {
    border-radius: 7px 7px 7px 7px;
    bottom: 10px;
    float: none;
    height: auto;
    margin-right: 10px;
    position: relative;
    right: -230px;
    width: 614px;
}
3
  • You mean you want to convert that XPath into a CSS selector for your stylesheet? Also, which div is div.PageHeaderDescription? It doesn't say in your XPath. Commented Jul 16, 2012 at 14:22
  • i already know the css path, div.PageHeaderDescription div table tbody tr td img but this applies the css to all images. Commented Jul 16, 2012 at 14:24
  • Can you show us us your html output? Commented Jul 16, 2012 at 14:55

3 Answers 3

2

You can use

div.PageHeaderDescription img:first-child {
border-radius: 7px 7px 7px 7px;
bottom: 10px;
float: none;
height: auto;
margin-right: 10px;
position: relative;
right: -230px;
width: 614px;

} To just access the first image or

    div.PageHeaderDescription > img {
border-radius: 7px 7px 7px 7px;
bottom: 10px;
float: none;
height: auto;
margin-right: 10px;
position: relative;
right: -230px;
width: 614px;

} To only access images within the PageHeaderDescription div.

Sign up to request clarification or add additional context in comments.

Comments

1

use this

div.PageHeaderDescription div table tbody tr td > img
{
border-radius: 7px 7px 7px 7px;
bottom: 10px;
float: none;
height: auto;
margin-right: 10px;
position: relative;
right: -230px;
width: 614px;
}

this will apply only to images inside the td

the > symbol is used to specify direct descendant

http://www.456bereastreet.com/archive/200510/css_21_selectors_part_2/

it has pretty good support in modern browsers too :-)

Comments

1

You could specify specific child nodes using the nth-child pseudo-class.

div.PageHeaderDescription div table tbody tr:nth-child(2) td:nth-child(2) img

nth-child MDN Reference

7 Comments

You could use this conditionally for IE6-8, if you can't add any other sort of specifier for that particular img http://selectivizr.com/
Or tr:first-child + tr td:first-child + td.
@ChristianBenincasa selectivizer is good to a point, but if you load content through AJAX for example, the AJAX loaded content loses its style
@BoltClock solution would work but can be a pain to maintain id go for direct descendant > selector as its better supported being a CSS 2.1 rule
The direct descendent would be good, but if OP needs to style only images that are contained within the second-child td, then wouldn't > fail?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.