开发者

CSS - How to prevent the browser from showing scrollbars when a div goes outside of the window?

I have a centered wrapper with following CSS:

div.wrapper {
width: 1170px;
padding-left:30px;
margin-top: 80px;
margin-bottom:20px;
margin-left: auto;
margin-right: auto;
position:relative;  
background-color:black; }

inside i have a div with following css:

position:absolute;
top:-26px;
left:517px;
height:63px;
z-index:3;

inside of this div is an image which has 759px width, that makes the wrapper grow larger and makes the browser show a v-scrollbar on lower display resolutions. what i want is to make the image go outside the wrapper but prevent the browser from showing the scrollbar, so that the right side of the image is only shown if your browser window is large enough and the wrapper keeps its 1200px width. i can't make it a background image because it goes over some of the other content. something that is compatible with >= IE7 would be nice.

i uploaded a pic of the page to show what i mean: http://img153.imageshack.us/img153/6070/hpx.jpg

the blue box is the wrapper, it has 1200px width and is ALWAYS centered in the window (unless then window is smaller than 1200px, then it scrolls) the red box is the开发者_运维技巧 image (the green bar is not part of it)


You can set overflow: hidden to the wrapper so that content that exceeds the dimensions of wrapper will not be shown.

see overflow


You are looking for #your_div { overflow: hidden; }, if you want your content to be hidden. Or #your_div { overflow: visible; } if you want your content visible outside the div.


The only method that springs to mind given your requirements is to move the inner element out of that wrapper div and position it in relation to the entire window:

<body>
  <div class="abs">the div with the image</div>
  <div class="wrapper">the wrapper div</div>
</body>

Unfortunately, this probably means you can't position it very well. You may need to use Javascript to get the width/height of the page and/or the position of the wrapper div, and calculate the offset accordingly. (You'll find questions on Stack Overflow for these bits.)


The problem lies with the img being inline. Not tested but you should 'display:block' the image and then float it or absolutely position it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜