Div inherit width from other div?

Hi Experts!

Can I make a div class inherit width from another div class?

Who is Participating?

Improve company productivity with a Business Account.Sign Up

David S.Connect With a Mentor Commented:
Yes and no.  An element can belong to multiple classes, an element may inherit some styles from its parent, and a style rule may be applied to multiple classes.  Otherwise the answer is probably "no".
AphXAuthor Commented:
Hmm okay. I have this problem:

<div class="div1">
<div class="div2">
<p>Some text</p>
<p>a lot of text</p>

Only div2 is adjusting it´s height depending on how much text there is. I want both divs to do the same thing.

Is it possible?
Chad HaneyConnect With a Mentor Chief Technology OfficerCommented:
if div1 has a height defined you can match the height with div2 by using height:100%;
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

AphXAuthor Commented:
Thank you guys!
David S.Commented:
You're welcome?

If ".div2" is floated then you need to tell its parent to contain it. Floating the parent of the floated element(s) is a good simple option in some cases and in others the PIE/Aslett approach works well.

More information: http://www.dynamicsitesolutions.com/css/layout-techniques/#clearing_floats
David S.Commented:
Oops. Typo. I didn't mean that first sentence to end in a question mark. It should be just:

You're welcome.
AphXAuthor Commented:

Thank you man!

I really appreciate your invaluable help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.