4

Is it possible to set max-width of a div to same value as width of its sibling (in angular6)?

In other words, can I set max-width of "child_two" to the same value as width of "child_one" with the constraint that I just know the width of "child_one" when it is rendered?

`<div class="parent-div">
   <div id="child_one" class="child-div"> </div>
   <div id="child_two" class="child-div"> </div>
 </div>`
2
  • 2
    Can you use flex CSS rules? Commented Nov 17, 2018 at 16:50
  • would be better without flexbox. Unless it is the only option? Commented Nov 17, 2018 at 16:52

1 Answer 1

7

You can bind the max-width style attribute of child_two to the offsetWidth of child_one, with the help of a template reference variable child1:

<div class="parent-div">
  <div id="child_one" class="child-div" #child1 > </div>
  <div id="child_two" class="child-div" [style.max-width.px]="child1.offsetWidth"> </div>
</div>

See this stackblitz for a demo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.