20
qbons
7y

I still hoping there will be parent selector in CSS...

Comments
  • 1
    me too...
  • 0
    It's planned since long time. Can't remember if the specs have been written yet.
  • 0
    @leny yep, i knew that. Thats why i still hoping that will be implemented soon.
  • 0
    Same... Just had a perfect situation for it and it's just so annoying knowing that it's coming but isn't there yet.
  • 1
    By the way, are there any known workarounds?
  • 1
    what about a unified pseudo class for placeholders, which can be styled with every css property?
  • 0
    @-xlf js the savior and i really hate it.
  • 0
    @Scrumplex i am sorry but i dont really get it. But, could you please explain to me how to apply your method in this simple situation. Lets say you have several <div> in a row which have blue background. But, you want to apply red background if the div contain <strong> tag. And this strong tag randomly placed in any div.
  • 1
    @qbons no I spoke about input and the pseudo tags for the placeholder defined for the input. You can use it but only do text modifications.
  • 1
    imo if you're doing something where you think you need a parent selector, you might be going about it the wrong way
  • 0
    Parent selectors sounds nice, but I think @DoctorDalek is right :).
  • 0
    @qbons that would be a single line of jquery. $('.yourBoldObject').closest('.rowToPutRedOn').addClass('makeRed');
  • 0
    Wouldn't this break the render process though? I've got away without parent selectors this far..

    Edit: some native variable media queries would be great tho.. pleeease.
  • 0
    @DoctorDalek oh please elaborate.
  • 1
    @Skipp yeah i know its really easy using js. But ugly af. I mean, i dont really like styling stuff with js. We already have CSS tho.
  • 0
    @qbons first of all you would have to pretty much rewrite every browsers method of painting if you want it to perform well. On top of that the idea is CSS is cascading styles. Waterfalls don't flow up. I can't think of any scenario where I would want to style something and cascade up.
  • 0
    @qbons true. That's why you just add a class that you have styled with css. You don't actually inject inline css. That's just awful.
  • 0
    @DoctorDalek no i mean please elaborate when you said "if you need parent selector, it could be im going to the wrong way". Maybe thats not really what you said, but i believe it is what you mean, right?
  • 0
    @Skipp nobody talking about injecting CSS code into element here. I already give an example about this condition. Please read my other comment about div and strong tag. If the content is static yes that will be really easy. I am talking about dynamic content which produce quite unpredictable content.
  • 1
    @qbons the whole premise of my statement is built around the idea of determining the style at the highest level possible. Using a parent selector violates that principle. To me, using a parent selector is the same as using GOTO
  • 0
    @qbons doesnt make any difference. If the content is static or available on page load - that jquery snippet will work. If you use ajax or partials or whatever makes your DOM change, just shove that single line of Js in a method and call it after you're done manipulating your dom. Simple as that :)
  • 0
    @DoctorDalek okay so it's all about principle.
  • 0
    @Skipp dude, really...
    I told you that its really easy to achieve parent selector using JS. And i dont really like it. I just give you an example about a case where parent selector is needed.
  • 0
    @qbons lol, i'm fully aware of what you're saying but the argument "i don't like it" when everyone is using it since that's the only easy way that works (at the moment) makes this whole discussion a bit redundant 😂
  • 1
    @qbons programming is all about principles. There is a reason we don't do things that breaks currently established rules
  • 0
    @Skipp thats why i am hoping for parent selector at the first place :))
  • 0
    @DoctorDalek please explain, how parent selector will break the rules? Thanks in advance
  • 1
    @qbons the whole idea of HTML and CSS is you have a big chunk, and then you whittle that down. There's no HTML element that says that it should really appear higher in the DOM. While this could be useful (stuff like enqueuing scripts in head but calling it in a partial) it breaks execution flow and just general structure. Remember that HTML are relatively dumb document types. They are not meant to be another programming language. While CSS does some seem like every selector has some logic to it (if body has class main, make links red), it's really just a map of styles to elements on the page.

    If you want to talk about regression issues, having something like a parent selector has the added potential of frustrating and non-intuitive debugging/behavior. Lets take the behavior. If you do something like a ^ .article {background: black} is that a direct parent or is that going up the tree until you hit .article? It's just confusing and can lead to way too many issues.
Add Comment