March 31, 2012

Apply background color to parent table th only

Question by Pavan Kumar

I have a table structure, where I can’t access jsp file to add class files. I have to manage it through css. In this case, I need to apply background color for 1st table all th’s. Not to nested table th’s. How can we do with css? Example : http://jsfiddle.net/qdDnJ/

Answer by Starx

The simplest way I know is to use the child selector

#yourtableId > tbody > tr > th { background: red; }

Demo

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!