0

I want to apply Css on class fancybox-inner which is the last parent of class main-content. I dont want to directly define the class and apply properties. Because I have multiple classes with the same name i.e fancybox-inner. So I want to target fancybox-inner on behalf of main-content.

HTML:

<div class="fancybox">

 <div class="fancybox-inner">

    <div class="main-content">

      <!--- Some Content ------>

    </div>

 </div>

<div>

What I have tried so far :

  .main-content < .fancybox-inner {
      width:1000px !important;
  }
Hassan Sardar
  • 4,413
  • 17
  • 56
  • 92

5 Answers5

4

Use : nth-last-child() Selector

http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_nth-last-child

updated Answer

.main-content:parent {//specify properties for fancybox-inner here}
Naren
  • 135
  • 1
  • 8
1

Is there a CSS parent selector?

Sorry to say but there is no way to do this the way you asked.

A possible solution is the go the other way.

.fancybox .fancybox-inner {
    // CODE HERE
}

This will target the fancybox class, then target the fancybox-inner (Which will ONLY target the one that is inside the fancybox class)

Hope this helps.

Community
  • 1
  • 1
Hamedar
  • 149
  • 1
  • 2
  • 11
  • Note though, if you have multiple .fancybox-inner in .fancybox, it'll target all of them. – Hamedar Mar 19 '14 at 06:38
  • 1
    to last comment of Hamedar, you could use '.fancybox > .fancybox-inner' to be more specific. As it will only target the div with class name '.fancybox-inner' which is directly inside or at first place in a div with class name '.fancybox'. Still it will target to all similar divs in relation but not beyond of that. – ravk Mar 19 '14 at 06:43
0

You can add one extra class to that element

<div id="mywrapper">
<div class="fancybox">

 <div class="fancybox-inner extra-class">

    <div class="main-content">

      <!--- Some Content ------>

    </div>

 </div>

</div>
</div>

Then your css will be :

 #mywrapper > fancybox >fancybox-inner {
      width:1000px !important;
  }
prady00
  • 721
  • 1
  • 6
  • 17
0

You might want to use jquery to access parent node and apply css to that. Possibly like,

$(".main-content").parent().css({'width':'1000px !important'});

dhunju
  • 71
  • 3
0

You could use wrapCSS property to set your custom class

$(".selector").fancybox({
    wrapCSS : 'my-custom-css-class'
});