简体   繁体   English

滚动页面不只是div CSS

[英]Scroll page not div CSS only

I have been struggling with this problem for a long time now, and although I have found a number of good solutions to parts of my problem, none of them seem to work combined, so I have decided to ask you. 我已经为这个问题苦苦挣扎很长时间了,尽管我已经找到了解决部分问题的好方法,但似乎没有一个可以结合使用,所以我决定问您。

Here is a scrn shot of the website: 这是网站的截图:

http://i.stack.imgur.com/6C0k1.jpg http://i.stack.imgur.com/6C0k1.jpg

What I'm hoping to achieve is to have a scroll bar appear on the far right of the page when content overflows the blue container, the div that has all my content in it, not the far right of the div itself, like it would if I set the div to overflow: auto or overflow: scroll . 我希望实现的是在内容溢出蓝色容器时在页面的最右边显示一个滚动条,蓝色容器中包含我所有的内容,而不是div本身的最右边,就像这样如果我将div设置为溢出:自动溢出:滚动

In other words, I would like the page to scroll, not my div. 换句话说,我希望页面滚动而不是div。

The site essentially consist of a body background, a div for the menu and a div for the content. 该站点主要由正文背景,菜单的div和内容的div组成。 The code is pretty messy, so I have left it out, but if you need it, just leave a comment and I will add it right away. 代码非常混乱,因此我将其省略了,但是如果您需要它,请留下评论,我会立即添加它。

Everything is supposed to be fixed as in remain like it is on the scrn shot, except for the content in the blue container to the right. 除了右边的蓝色容器中的内容之外,所有内容都应该像在scrn镜头上一样保持固定。 I initially figured that setting everything except the container to position:fixed would work and trigger a scroll bar to appear for the page that could be used to scroll through the div, but it didn't. 最初,我发现将除容器之外的所有内容都设置为position:fixed可以正常工作,并触发滚动条出现在可用于在div中滚动的页面,但没有成功。 This doesn't work though, as any visible overflow in the container just 'leaves' the page; 但是,这不起作用,因为容器中任何可见的溢出都只是“离开”了页面; it doesn't trigger a scroll bar. 它不会触发滚动条。

As I've also pointed out in the scrn shot, the container-div has padding on the top and bottom and is also slightly transparent. 正如我在scrn镜头中所指出的,container-div在顶部和底部都有填充,并且也略微透明。

These two features seem to make things even more difficult. 这两个功能似乎使事情变得更加困难。 The padding, because setting overflow: visual makes content overflow, and thereby be visible, even through padding. 填充,因为设置了溢出:视觉使内容溢出,因此即使通过填充也可以看到。 The transparency is an issue, since I can't just cut out the padding and give it a z-index that's higher than the content itself, in order to hide it; 透明度是一个问题,因为我不能为了保留它而只剪掉填充并为其提供一个高于内容本身的z索引; it will still be visible through it. 通过它仍将可见。 The background image is set at a percentage or set to 'cover' (still figuring out which one works best), so cutting out the padding with the segment of the background image it covers, will not work either. 将背景图像设置为某个百分比或设置为“覆盖”(仍在确定哪一个效果最好),因此用背景图像覆盖的部分切掉填充也将不起作用。

I hope I presented my problem and the issues clearly enough. 我希望我清楚地介绍了我的问题和问题。 If you have any questions or any feedback, please leave a comment. 如果您有任何疑问或反馈,请发表评论。

Thank you in advance for any replies, Magnus 谢谢您的任何答复,马格努斯

NOTE: This is a repost of an early question that was trashed by someone who didn't bother reading through it properly before rating it down. 注意:这是一个早期问题的转贴,该问题被某人浪费了,因为有人没有认真阅读它,然后才对其评分。 The question essentially died afterwards. 这个问题后来基本消失了。 I have tried to make things even more clear this time, so I'm sorry if I repeat myself. 这次我试图使事情变得更加清晰,所以如果我重复我自己,我感到抱歉。 This is also the reason why my post is so long this time. 这也是我这次的帖子这么长的原因。

Something like this? 像这样吗

Demo : http://jsfiddle.net/6R7c2/ 演示http : //jsfiddle.net/6R7c2/

HTML: HTML:

<div id="top">Top</div>
<div id="middle">
    <div>Content
    </div>
</div>
<div id="bottom">Bottom</div>

CSS: CSS:

html,body{
    width:100%;
    height:100%;
    margin:0;
}
#top,#bottom{
    height:10%;
    background:blue;
    color:white;
}
#middle{
    height:80%;
    overflow:auto;
}

#middle>div{
    height:10000px;
    border:25px solid red;
}

It can be something like this 可能是这样的

see http://jsfiddle.net/QfsvB/ 参见http://jsfiddle.net/QfsvB/

CSS 的CSS

div.scroll 
{
background-color:#00FFFF;
width:100px;
height:100px;
overflow:scroll;
}

HTML 的HTML

<div class="scroll">You can use the overflow property when you want to have better control of the layout, the overflow property specifies what to do if the content of an element exceeds the size of the element's box.</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM