我试着用浏览器的宽度来扩展这个div。我从here上读到,您可以使用{position:absolute; left: 0; right:0;}来实现这一点,就像在jsfiddle中那样:http://jsfiddle.net/bJbgJ/3/
但问题是我当前的#container有一个{position:relative;}属性,因此如果我对子div应用{position:absolute},它将只引用#container。有没有办法仍然将我的孩子div扩展到#container之外?
发布于 2019-04-18 00:34:01
我有一个例子,我需要制作一个carousel,并将其包装在父元素之外。您可以将子元素设置为具有一个最大宽度,并将父元素设置为具有特定数量的pixels...or的最大宽度。通过这种设置,我们的子组件将自己扩展到父组件之外。JSFiddle
.parent {
// our parent container has 20px margins on each side so we set its max width accordingly
max-width: calc(100vw - 20px)
}
.child {
// set the child to wrap the entire viewport width. Account for any margins from the parent and offset them with a negative margin
width: 100vw;
transform: translateX(-20px);
}https://stackoverflow.com/questions/12849717
复制相似问题