Jump to content

CSS HTML apply style to child if parent got class

Joveice
Go to solution Solved by Joveice,
1 minute ago, Minibois said:

You can have parent green or parent decide the text color I guess, if that is what you're looking for.

Not sure but I figured out what I had to do to get what I would like.

 

So I were doing .parent .green > p. and that dident work but it worked by removing the space in .parent.green.

 

So Yea I guess it was simper than I tought

 

Sorry for a post that was solved so fast by myself :3 as I just stumbled over it.

Question is probably really simple but I have no idea, and all my google searches result in "how to apply css to parent if child got class" instead of the other way as I want.

 

<div class"parent">
  <div class"child">
    <p>This text is white</p>
  </div>
</div>

<div class"parent green">
  <div class"child">
    <p>This text is green</p>
  </div>
</div>

I do not need how to apply colors as this is just a example I just need the way you do it (I think it has to do with ">" ? )

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

You can have parent green or parent decide the text color I guess, if that is what you're looking for.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Minibois said:

You can have parent green or parent decide the text color I guess, if that is what you're looking for.

Not sure but I figured out what I had to do to get what I would like.

 

So I were doing .parent .green > p. and that dident work but it worked by removing the space in .parent.green.

 

So Yea I guess it was simper than I tought

 

Sorry for a post that was solved so fast by myself :3 as I just stumbled over it.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

.parent {
	color:green;
}

.child {
	color:inherit;
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×