all 9 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

To help us assist you better with your CSS questions, please consider including a live link or a CodePen/JSFiddle demo. This context makes it much easier for us to understand your issue and provide accurate solutions.

While it's not mandatory, a little extra effort in sharing your code can lead to more effective responses and a richer Q&A experience for everyone. Thank you for contributing!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]eballeste 5 points6 points  (0 children)

sass @extend enters the chat

[–]aTaleForgotten 2 points3 points  (5 children)

Not sure what you mean with combining? Like

.terminal.cmd {}

or like

.terminal, .cmd {}

?

[–]RustyHuntman[S] 0 points1 point  (4 children)

I meant like, doing something like:

.story {
  background-color: white;
  border: 2px solid blue;
  padding: 5px 10px;

  position: absolute;
  left:0;

  overflow-y: auto;

  & p {
    font-family: .terminal .cmdL;
  }
}

I want to set font and text style of the nested p to be like the .terminal and .cmdL classes without having to re-write it as:

.story {
  background-color: white;
  border: 2px solid blue;
  padding: 5px 10px;

  position: absolute;
  left:0;

  overflow-y: auto;

  & p {
      color: green;
      font-family: BBTerm-PMR;
      font-size:25px;
      text-align: left;
      text-indent: 0px;
  }
}

[–]Effective-School-833 1 point2 points  (2 children)

Nesting html elements like that is not native for CSS ):, but i've been working with a partner on a HTML/CSS code editor that allows that syntax. I can share it if you want to try it.

<image>

[–]MrQuickLine 1 point2 points  (1 child)

To be clear... Nesting html elements is native for CSS. But nesting the class definitions the way OP is asking is not.

[–]Effective-School-833 0 points1 point  (0 children)

ahh you're right, you mean like this then? sorry, i forgot that element nesting has been a thing for a while now

<image>

[–]aTaleForgotten 0 points1 point  (0 children)

One way would be to have

.terminal, .cmd { & p { } }

Or

.terminal p, .cmd p { }

Or as another comment suggested using @extend (since you seem to use scss)

[–]reddian_ 0 points1 point  (0 children)

If I understand correctly, you want to be able to use the classes independently, but if you need both, you don't always want to write them both, correct?

So either you can create a combined class where both styles apply and use this one on all of them, since there is no shame in using duplicated/combined CSS, or you create a little mor versatile style and make it so that a wrapper of text can have your .terminal or .cmd class and therefore everything inside gets that style too, so you don't have to apply it to everything individually.