[英]Extend one div (among others) beyond parent container
I have a certaing layout of nested divs. 我有一个嵌套的div的一定布局。 One of them I would like to expand beyond its parent.
我想扩展其中之一。 However, with this nesting it's not that simple - I think.
但是,这种嵌套并不是那么简单-我认为。
Html: HTML:
<div class="wrapper">
<div class="gridcontent">
<div class="gcrow single-column">
<div class="gccolumn">
<div class="gccolumn-inner">
<div class="gcitem">
<p>Extend to .wrapper width</p>
</div>
</div>
</div>
</div>
</div>
</div>
I can't change the html, and there may be other .gcrow
s that need to stay inside the container. 我无法更改html,并且可能还有其他
.gcrow
需要保留在容器内。 Is this possible to to at all? 这有可能吗?
Fiddle here . 在这里摆弄 。
I hope my question makes sense. 我希望我的问题有道理。
try something like this 尝试这样的事情
.gcrow {
position: relative;
overflow: visible;
}
.gcitem {
position: absolute;
right: 0;
top: 0;
}
For your current HTML structure you can use .gcrow:first-child
and set min-width: 100vw
which is same as wrapper
width if you remove default margin and padding from html, body
. 对于当前的HTML结构,您可以使用
.gcrow:first-child
并设置min-width: 100vw
,如果您从html, body
删除默认边距和填充,则该宽度与wrapper
宽度相同。
You can use position: relative
, left: 50%
and to make it center just add transform: translateX(-50%)
, here is Fiddle
您可以使用
position: relative
, left: 50%
并使其居中,只需添加transform: translateX(-50%)
,这就是Fiddle
body, html { margin: 0; padding: 0; } * { box-sizing: border-box; } .wrapper { width: 100%; padding-left: 20px!important; padding-right: 20px!important; border: 1px solid pink; } .gridcontent { width: 100%; max-width: 1018px; border: 1px solid #333; margin: 0 auto; } .gcrow { max-width: 100%; width: 100%; border: 1px solid #f00; } .gcrow:first-child { min-width: 100vw; position: relative; left: 50%; transform: translateX(-50%); }
<div class="wrapper"> <div class="gridcontent"> <div class="gcrow single-column"> <div class="gccolumn"> <div class="gccolumn-inner"> <div class="gcitem"> <p>Extend to .wrapper width</p> </div> </div> </div> </div> <div class="gcrow single-column"> <div class="gccolumn"> <div class="gccolumn-inner"> <div class="gcitem"> <p>Leave me alone</p> </div> </div> </div> </div> </div> </div>
Also its box-sizing: border-box
not box-border
还有其
box-sizing: border-box
而不是box-border
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.