Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically set max-width of sibling in angular

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>`
like image 527
Jymbo Avatar asked Oct 25 '25 14:10

Jymbo


1 Answers

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.

like image 56
ConnorsFan Avatar answered Oct 27 '25 04:10

ConnorsFan