-3

I have a div as follows:

<tr class="section">
   <td>some content here</td>
   <td class="info">content 2 here</td>
</tr>

css:

.section{
   //style here
 }

.info{
   //another style here
}

In this case, i don't want to apply the section style in the in info.

How to do that?

Dennis Xavier
  • 101
  • 1
  • 14
  • 5
    That HTML is invalid. `td` can only be a child of `tr`. – connexo Mar 21 '18 at 12:43
  • it's invalid as said but if we consider them span ... you cannot, you simply need to revert back the style BUT not all of them (display,opacity, etc etc) – Temani Afif Mar 21 '18 at 12:46
  • Also, you cannot prevent style inheritance - you can only overwrite unwanted styles coming from a parent element. – connexo Mar 21 '18 at 12:46
  • 1
    Asked and answered [here](https://stackoverflow.com/questions/958170/how-do-i-prevent-css-inheritance) – sideroxylon Mar 21 '18 at 12:47

2 Answers2

0

You can use the :not selector in the following way: .section *:not(.info)

(I changed your HTML a bit to make it valid)

.section{
   color: red;
 }

.section *:not(.info){
   color: green;
}
<div class="section">
   <span>some content here</span>
   <span class="info">content 2 here</span>
</div>
Johannes
  • 64,305
  • 18
  • 73
  • 130
  • Thanks @Johannes, That's good, but the _section_ class static one, should not change anything here, for the "_content 2_" i just wanted to exclude the "section" style. – Dennis Xavier Mar 21 '18 at 13:20
  • why you re-opened this question too ... you don't like when we close a question you answer ... – Temani Afif Mar 21 '18 at 13:46
  • the so-called "duplicate" is from 2009, and under the accepted answer there is a comment (with 9 upvotes) that this answer is outdated – Johannes Mar 21 '18 at 14:09
  • @Johannes that doesn't make this any less of a duplicate. There are 10 other answers on that question. – James Donnelly Mar 21 '18 at 15:33
0

Your should use td only if you are using an HTML table instead you can use div's or a more semantic tag... check here

In the css you can overwrite your parent class when you are inside of it like this..

.section .info{
   //overwrite style here
 }
Renzo Calla
  • 7,486
  • 2
  • 22
  • 37