-1

Im creating a form using Fieldset for Formatting purpose. I would like to style those fieldsets, but I want to do different styles depending on if either the Fieldset contains a Legend or not.

So, if the Fieldset contains a Legend tag, I want to apply one style.

If the Fieldset doesnt contains a Legend tag, I want to apply another style.

Is that possible with CSS? Thanks.

Gekyzo
  • 41
  • 5
  • 2
    No, this is not possible with CSS as there is no parent selector in CSS. – David Thomas Jan 18 '17 at 19:35
  • what kind of styling do you want to apply. There might be a trick if styles to apply are or not compatible with that trick .... – G-Cyrillus Jan 18 '17 at 19:37
  • @GCyrillus, what? There are no tricks here—you cannot ascend in CSS. [It's proposed for CSS4](https://www.w3.org/TR/2011/WD-selectors4-20110929/#subject). – André Dion Jan 18 '17 at 19:40
  • @AndréDion yes, can be a few tricks to **mimic** this behavior , if not, i would not write so ;) depending on what the op wants, i could propose something or not – G-Cyrillus Jan 18 '17 at 19:43
  • @AndréDion basicly, you have position:relative and absolute, for mouse events you have pointer-events .... but only the structure and kind of styling expected can tell if it be done, if it is about font-family: forget it :) – G-Cyrillus Jan 18 '17 at 19:45
  • @GCyrillus, and that pertains to targeting a parent/ancestor how? – André Dion Jan 18 '17 at 19:47
  • @AndréDion you do not target it , you use it or put it of the way from mouse event on its own level – G-Cyrillus Jan 18 '17 at 19:48
  • @AndréDion i had to search for old examples : http://codepen.io/gc-nomade/pen/bjcql & http://codepen.io/gc-nomade/pen/pDnuc You would search for a parent selector in the first place to apply those styles, but is there really a need there ? ;) – G-Cyrillus Jan 18 '17 at 19:51

1 Answers1

-1

There are no parent selectors in CSS, not even in CSS3.

https://css-tricks.com/parent-selectors-in-css/


Of course, it may be acceptable for you to apply the style to the legend tag instead of the fieldset tag. In which case it would simply be:

fieldset legend {
    /* Styles for legend tags within fieldset tags */
}
Erik Berkun-Drevnig
  • 2,306
  • 23
  • 38