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
  • 204,283
  • 31
  • 260
  • 272
Ilja Den
  • 53
  • 8

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,789
  • 33
  • 60