1

I guess I am spoiled with JavaScript. If you want to change something about the parent, you can code something like parentNode.style.etc.

 
<TABLE id="hasID">
  <TBODY>
    <TR>
      <TD>
        <IMG id="hasID2" src="somePicture.png">
        <IMG id="hasID3" src="someOtherPicture.png">
      </TD>
    </tr>
    <tr>
      <td>other stuff</td>
    </tr>
  </tbody>
</table>

As you can see from my code table has an id, and the img tags have ids. What I would like to do is add a stype class to the first TD, so that all the images are aligned to the left or middle, that kind of thing.

However, here is a tricky part, I don't want to user JavaScript, because it looks to slow. Everything starts out on the right, and then jump to the center, after everything is loaded.

Also, here is a second tricky part. I can't change add a class to the TD, because it generated by JSF.

So my main question is can I do this with CSS.

UPDATE:

I don't really need to reference a parent. Referencing a child will also work for me.

GC_
  • 1,613
  • 4
  • 22
  • 37
  • possible duplicate of [CSS parent selector](http://stackoverflow.com/questions/1014861/css-parent-selector) – Andy E Oct 28 '10 at 19:51
  • I had a little typo, but I not sure if it matters. Referencing the child would also work for me. – GC_ Oct 28 '10 at 20:00

3 Answers3

1

You can't select a parent via CSS. It was proposed as a feature but it's not even close to implementation.

I will suggest that you move any javascript you have to just after the content above, which means that it will run as soon as that part of the section is rendered, thus removing any delay.

<TABLE id="hasID">
  <TBODY>
    <TR>
      <TD>
        <IMG id="hasID2" src="somePicture.png">
        <IMG id="hasID3" src="someOtherPicture.png">
      </TD>
    </tr>
    <tr>
      <td>other stuff</td>
    </tr>
  </tbody>
</table>

<script type="text/javascript">
    var img = document.getElementById("hasID2");
    img.parentNode.style.textAlign = "right";
</script>

Inline Javascript is OK to use in these scenarios.

Marko
  • 68,081
  • 26
  • 118
  • 153
0

Sorry no way to select parent in css.

Is there a CSS parent selector?

Community
  • 1
  • 1
sunn0
  • 2,691
  • 1
  • 21
  • 24
0

Not sure if this will help, but I'll mention that you can add classes using JSF with styleClass="", depending on how you are generating the table. There is also a columnClass="" if you are putting these in a datatable.

scruffs
  • 1
  • 1