0

Is there a way to write style for class parent that contains class child ? For example I want class parent which has child This is what i have:

<div class  = "parent">
    <div class  = "child">
    </div>
</div>

And here is what I want it to be:

<div class  = "parent" width = "300px">
    <div class  = "child">
    </div>
</div>

CSS should be something like this ?

.child .parent {
   width: 300px
}
j08691
  • 190,436
  • 28
  • 232
  • 252
Ilja Den
  • 53
  • 7

1 Answers1

0

Here is a jQuery solution. You select the child element, then apply the width to the parent element.

$(function() {
  $('.child').parent().width('200px');
});
.parent {
  background: blue;
}
.child {
  background: gray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<div class="parent">
  <div class="child">
    <span>content</span>
  </div>
</div>
Zack
  • 2,619
  • 30
  • 58