根据你的建议原建议(确定负差),我尝试并提出了使用百分单位进行动态浏览器的类似方法:
<><><><>>><>>>>><>>>>>>
<div class="grandparent">
<div class="parent">
<div class="child">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore neque repellat ipsum natus magni soluta explicabo architecto, molestias laboriosam rerum. Tempore eos labore temporibus alias necessitatibus illum enim, est harum perspiciatis, sit, totam earum corrupti placeat architecto aut minus dignissimos mollitia asperiores sint ea. Libero hic laudantium, ipsam nostrum earum distinctio. Cum expedita, ratione, accusamus dicta similique distinctio est dolore assumenda soluta dolorem quisquam ex possimus aliquid provident quo? Enim tempora quo cupiditate eveniet aperiam.</p>
</div>
</div>
</div>
<>CSS:
.child-div{
margin: 0 -100%;
padding: 0 -100%;
}
.parent {
width: 60%;
background-color: red;
margin: 0 auto;
padding: 50px;
position:relative;
}
.grandparent {
overflow-x:hidden;
background-color: blue;
width: 100%;
position:relative;
}
不利幅度将使得内容从父母四肢解中流出。 因此,我确定了<条码>:100%;,将内容推回Chlid DIV的原始边界。
负差还将使child子的总宽度从浏览室中扩大,从而形成横向的滚动。 因此,我们需要通过向祖父母DIV(父母离异的父母)适用<条码>over-x:隐藏的<>/条码>,来揭穿外衣:
www.un.org/Depts/DGACM/index_spanish.htm 这里是JSfiddle。
我已尝试过Nils Kaspersson sleft:calc(-50vw + 50%)
;它在 Chrome和amp做了精干的罚款;FF(不是确定IE, 还是),直到我发现Safaribrowsers没有适当做。 我希望他们在我实际上喜欢这一简单方法时就确定这一点。
This also may resolve your issue where the Parent DIV element has to be position:relative
这一工作方式的2个缺点是:
- Require extra markup (i.e a grandparent element (just like the good ol table vertical align method isn t it...)
- The left and right border of the Child DIV will never show, simply because they are outside of the browser s viewport.
Please let me know if there s any issue you find with this method ;). Hope it helps.