0

i want to apply css before p tag td. other td should be not effected

<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
  <td>heading</td>
    <td>some data</td>
      <td><p class="may-class">Date</p></td>
 </tr>
</table>
Lumi Lu
  • 3,213
  • 1
  • 9
  • 20
MIke J.
  • 61
  • 1
  • 7

2 Answers2

2

What it sounds like you are looking for is a parent selector, which CSS doesn't contain (yet...) http://css-tricks.com/parent-selectors-in-css/

What I would do is apply a class to the td that you want to style. If you can't access the HTML than maybe you can style the p tag inside of the td with a direct child selector:

td > p { ... }

Refer to this question for ways to style it using Javascript: Is there a CSS parent selector?

Community
  • 1
  • 1
DMTintner
  • 13,235
  • 4
  • 32
  • 31
1

When the td with the p-class is always the only and last element of the tr you can use :last-child css styling.

Like:

tr td:last-child {
    color:red;
}

EDIT: It doesnt work with CSS. CSS cant get the parent of an element. Use jQuery/javascript instead:

jQuery('.may-class').parent().addClass('someClass');
Der Vampyr
  • 933
  • 1
  • 6
  • 13
  • I have more td. i want apply only befor p tag td
    heading some data

    Date

    some data some data
    – MIke J. Nov 13 '14 at 09:25
  • Than you have to use the javascript/jquery approach and add a class to the parent like shown in my edit. – Der Vampyr Nov 13 '14 at 09:30
  • can it will possible to achieve this using css – MIke J. Nov 13 '14 at 09:42
  • Like DMTintner wrote: It is not possible to do this with CSS!. (Read his links (i recommend the second one) If you want to add a class to the td before your p you need `javascript` or `jQuery` – Der Vampyr Nov 13 '14 at 09:55