在我更好地理解了您的问题之后,这里有另一个答案:)
Look at this codepen: https://codepen.io/spierala/pen/wvBWaWV
For the CSS I also used bootstrap flex classes, but the main magic is position: absolute
on the div.content-sidebar
so it can "escape" of its parent container). Also the parent container div.content-container
is not allowed to have positioning itself to make that work.
The app-component must decide over giving footer and header a margin.
The routed component inside the router outlet must decide over the margin of the div.content
. Because div.content-sidebar
is absolute positioned it can not influence the width of div.content
anymore. We have to fix that manually by adding margin if the content-sidebar is visible.
So you can use Angular to add the css classes / styling which are needed for adding or removing the margins in app-component and in the routed components - depending on the content-sidebar visibility.
How will app-component and routed component know? You could introduce a Angular service which will hold the information if a sidebar is visible or not. The routed component could set that information. app-component reads it.
EDIT: regarding the "escape"... if header and footer have fixed heights then you could use negative margins on the content-sidebar instead of the position:absolute approach
If footer and header have a height of 50px then the div.content-sidebar
margins look like this:
.content-sidebar {
margin-top: -50px; // - header height
margin-bottom: -50px; // - min footer height
}
我在这里创建了另一个codepen:https ://codepen.io/spierala/pen/PowzmzL您还将看到,div.content
由于content-sidebar并未定位,因此不再需要边距absolute
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句