Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Style Parent Container using Child’s Class/ID

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #24987
    zaidpirwani
    Member

    Hi,

    Though the title almost says it all, let me just rephrase it here for better understanding…

    I need to know if it is possible to somehow use the class/id of a child element to style it’s parent or container element using CSS

    Sample Code (taken from WordPress / Thesis theme):




    OTHER DIV's and stuff

    This is the code which I am getting, because of my PHP code, I sometimes get the linked-list class and sometimes I don’t, now I want to know if I can somehow use that linked-list class (which is the class of a child element) to apply styles on the main container DIV, suppose that I don’t want to use the class of the container DIV, I need to make the linked-list posts different from others, all others don’t have this class, but this class is currently only appearing in the heading, H2.

    I may be able to get this class in the container DIV, but I wanted to ask here first, if it is possible to style the main container DIV using the linked-list class…

    ANY kind of help or guidance will be greatly appreciated.

    Thanks in advance.

    #80055
    jamygolden
    Member

    So basically, you want to target an element that contains a specific element?

    You are not able to do this with CSS alone, however you could achieve this with the help of javascript.

    #80063
    Luminated
    Member

    I believe Jamy_za is right…what you’re thinking violates the cascading nature of CSS, which is always a downstream direction. I don’t believe you can ‘reverse gears’ essentially, not without the aid of Javascript.

    Although, I can easily see future versions of CSS possibly integrating that type of functionality.

    #80049
    zaidpirwani
    Member

    Thanks @jamy_za and @Luminated.

    @jamy_za: Can you please provide me some kind o link etc for doing this through javascript.


    @Luminated
    : Yes I had also thought of that, as CSS works from top to bottom, though I don’t think there is anything like this currently under consideration for CSS3, but only time will tell.

    If it was possible, then it would have been so cool…..

    #80037
    Luminated
    Member

    If I’m not mistaken, I think you can also do this with PHP…I’m probably wrong and I think I’d need to see the PHP to be sure, but now you’ve got me thinking… :)

    #80013
    Rob MacKay
    Participant

    $(“h2.linked-list”).parent().css(‘background’, ‘red’); is an example :)

    #80005
    zaidpirwani
    Member

    @Luminated: I hope to see something out of all that thinking you are now doing for me…. Thanks..

    #79975
    zaidpirwani
    Member

    @Robskiwarrio: thanks for the code snippet, but could you please be a little more specific and tell me how to use it… a reference link etc will do wonders.. :)

    Thanks by the way..

    #79572
    zaidpirwani
    Member

    Hey guys, don’t leave me alone like this..

    #79575
    jamygolden
    Member







    Hello



    Hello Again




    Copy and paste the above example into an html file.
    Also, have a look at this website

    #79579
    zaidpirwani
    Member

    Thankyou @jamy_za and also thanks to all others….

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘CSS’ is closed to new topics and replies.