您可以使用最小寬度爲500px或寬度爲100%的容器,具體取決於您是否需要滾動條或根本沒有;添加相對位置,並溢出隱藏,然後添加另一個容器,這是您的設置寬度爲500px,左右邊距爲自動。將你的內容放在內部容器中,使用絕對位置;在這種情況下你的#banner會是正確的:-50px;
我在這裏修改您的提琴:http://jsfiddle.net/s95uz/14/
<style type="text/css">
#main {
min-width:500px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
#inside{
width:500px;
margin:0 auto;
height:100%;
position:relative;
background: red;
}
#banner {
background: green;
position: absolute;
right: -50px;
width: 150px;
height: 300px;
}
#content {
width: 400px;
height: 500px; /* Simulate content */
background: blue;
}
</style>
<div id="main">
<div id="inside">
<div id="banner">
I want this to not create a horizontal scrollbar, when the window/frame is too narrow.</div>
<div id="content"></div>
</div>
</div>
此外,您還可以改變witdh或利潤率,使旗幟仍然在頁面 –
我不想隱藏它。對不起,也許這不清楚:) – Znarkus
但是,如果您調整窗口大小,那麼橫幅不在窗口中,而且您不需要滾動條......這與隱藏橫幅時沒有足夠的空間在視口中?無論如何,使用響應式CSS您可以更改橫幅的屬性,也可以將其移動到內容中,或更改寬度。 –