문제

I need to align an element to the edge of its 'grandparent'.

Here's an example of the code:

<div id='grandparent'>
  <div class='parent' style='display:inline-block'>
    <div class='child'></div>
  </div>
  <div class='parent' style='display:inline-block'>
    <div class='child'></div>
  </div>
  <div class='parent' style='display:inline-block'>
    <div class='child'></div>
  </div>
  <div class='parent' style='display:inline-block'>
    <div class='child'></div>
  </div>
</div>

So the .parent elements are going to be positioned inline which will depend on the width of the #grandparent element. I need each .child element to be positioned to the left edge of #grandparent.

Any chance this is possible without javascript?

도움이 되었습니까?

해결책

Assign a relative position to the grandparent and an absolute position to the child elements. Then use the top, left, bottom, right properties of the children elements (which is with respect to the grandparents bounds) to get your desired effect.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top